Display output of Javascript function - javascript

I have a javascript function that outputs the date modified of a sharepoint list.
Here is my code:
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var lists = web.get_lists();
var list = lists.getByTitle("Tasks");
ctx.load(list, "LastItemModifiedDate");
ctx.executeQueryAsync(
function() {
var lastmodified = list.get_lastItemModifiedDate();
},
function() {}
);
Which I got from this link. But I am unsure of how to display the output from the function. I tried to display the output in the html tag but still no luck.

Have you tried something like this after you capture the lastmodified date?
// Names are generic and can be changed
var displayElement = document.getElementById("lastModifiedDisplay");
displayElement.innerHTML = lastmodified
document.getElementById

Related

How to change title of an event?

I am trying to update the title of the events in the last 7 days in a specific calendar, when an user submits a form.
I have this code now:
function myFunction() {
var form = FormApp.openById('1g4gA7glYWRKOVqOi3z3qxyEGbJgaSg_2Jkry_uOp0Cc');
var responses = form.getResponses();
var len = responses.length;
var last = len - 1;
var items = responses[last].getItemResponses();
var email = responses[last].getRespondentEmail();
var equipment = items[1].getResponse();
var cal = CalendarApp.getCalendarsByName(equipment);
var d = new Date();
var ms = d.getTime();
var sevenDays = 7*24*60*60*1000;
var minus7daysMs = ms - sevenDays;
var minus7days = new Date(minus7daysMs);
Logger.log('Number of events: ' + minus7days);
var events = cal[0].getEvents(minus7days, d);
var title = events.getName;
Logger.log('Event title: ' + title);
events.setTitle('Returned');
}
However, I get that error when running the code: TypeError: events.setTitle is not a function myFunction # update.gs:22
I tried many different ways of doing it, but it always ends with an error. Could you please tell me what I am doing wrong?
Thank you very much for your help!
From your showing script, getEvents(startTime, endTime) returns CalendarEvent[]. And setTitle(title) is a method of Class CalendarEvent. In your script, at events.setTitle('Returned'), setTitle is used to an array. I think that the reason of your issue is due to this. When you want to change all events in events with setTitle('Returned'), how about the following modification?
From:
events.setTitle('Returned');
To:
events.forEach(e => e.setTitle('Returned'));
By this modification, the title of all events in events are changed.
References:
getEvents(startTime, endTime)
setTitle(title) of Class CalendarEvent

Put variable name in JSON Array (fetched by an api)

I am very new to Javascript but I will try to put this in convenient way. I am having this api where I am fetching the rank of a crypto (Ripple; currently ranked 7 and is subject to change overtime ), code below:
function myFunction() {
var url = "https://api.coinpaprika.com/v1/coins/xrp-xrp";
var XRPresponse = UrlFetchApp.fetch(url);
var XRPjson = XRPresponse.getContentText();
var XRPdata = JSON.parse(XRPjson);
var XRPrank = XRPdata.rank;
}
Now this is another function for an api where I extract other infos (having 5000+ crytos listed, including ripple)
function myXRP() {
var url = "https://api.coinpaprika.com/v1/tickers";
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
var XRP = data[7].symbol;
// Here instead of [7], I need to put the value extracted from XRPrank above so that whenever the rank is changed I get the latest value on data.[].
If someone could please advise.
In JavaScript there are several ways to achieve what you are looking for. The following is an adaptation of your current code with what I think are the minimal changes that you have to do, 1. use return followed by XRPrank 2. Call myFunction from myXRP and replace the data index by XRPrank.
function myFunction() {
var url = "https://api.coinpaprika.com/v1/coins/xrp-xrp";
var XRPresponse = UrlFetchApp.fetch(url);
var XRPjson = XRPresponse.getContentText();
var XRPdata = JSON.parse(XRPjson);
var XRPrank = XRPdata.rank;
return XRPrank; // add this
}
function myXRP() {
var url = "https://api.coinpaprika.com/v1/tickers";
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
var XRPrank = myFunction(); // add this
// var XRP = data[7].symbol; instead of this
var XRP = data[XRPrank].symbol; // use this
}
Resources
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions

Get String Value of Blob Passed to e.parameter in Apps Script

I'm using this code to get a blob passed to a function:
function submit(e){
var arrayBlob = e.parameter.arrayBlob;
Logger.log("arrayBlob #2 = " + arrayBlob.getDataAsString());
This is the error I get:
Execution failed: TypeError: Can not find getDataAsString function in
the Blob object.'arrayBlob'
How do I get the string value of this blob?
Here is my code:
function showList(folderID) {
var folder = DocsList.getFolderById(folderID);
var files = folder.getFiles();
var arrayList = [];
for (var file in files) {
file = files[file];
var thesesName = file.getName();
var thesesId = file.getId();
var thesesDoc = DocumentApp.openById(thesesId);
for (var child = 0; child < thesesDoc.getNumChildren(); child++){
var thesesFirstParagraph = thesesDoc.getChild(child);
var thesesType = thesesFirstParagraph.getText();
if (thesesType != ''){
var newArray = [thesesName, thesesType, thesesId];
arrayList.push(newArray);
break;
}
}
}
arrayList.sort();
var result = userProperties.getProperty('savedArray');
arrayList = JSON.stringify(arrayList);
var arrayBlob = Utilities.newBlob(arrayList);
Logger.log("arrayBlob #1 = " + arrayBlob.getDataAsString()); // Here it`s OK
var mydoc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setWidth(550).setHeight(450);
var panel = app.createVerticalPanel()
.setId('panel');
panel.add(app.createHidden('arrayBlob', arrayBlob));
var label = app.createLabel("Selecione os itens desejados").setStyleAttribute("fontSize", 18);
app.add(label);
arrayList = JSON.parse(arrayList);
panel.add(app.createHidden('checkbox_total', arrayList.length));
for(var i = 0; i < arrayList.length; i++){
var checkbox = app.createCheckBox().setName('checkbox_isChecked_'+i).setText(arrayList[i][0]);
Logger.log("arrayList[i][0] = " + arrayList[i][0]);
Logger.log("arrayList[i] ====> " + arrayList[i]);
panel.add(checkbox);
}
var handler = app.createServerHandler('submit').addCallbackElement(panel);
panel.add(app.createButton('Submit', handler));
var scroll = app.createScrollPanel().setPixelSize(500, 400);
scroll.add(panel);
app.add(scroll);
mydoc.show(app);
}
function submit(e){
var arrayBlob = e.parameter.arrayBlob;
Logger.log("arrayBlob #2 = " + arrayBlob.getDataAsString());
// Continues...
}
I'd like the solution worked with more than one user simultaneous using the script.
Update:
Add a global variable OUTSIDE of any function:
var arrayBlob = Utilities.newBlob("dummy data");
function showList(folderID) {
Code here ....
};
Check that the code has access to the blob:
function submit(e){
Logger.log("arrayBlob.getDataAsString(): " + arrayBlob.getDataAsString());
//More Code . . .
}
This solution eliminates the need of embedding a hidden element in the dialog box with a value of the blob.
You won't need this line:
panel.add(app.createHidden('arrayBlob', arrayBlob));
There are other changes I'd make to the code, but I simply want to show the main issue.
Old Info:
In the function showList(), the method getDataAsString() works on the blob named arrayBlob.
Logger.log("arrayBlob #1 = " + arrayBlob.getDataAsString()); // Here it`s OK
In the function, submit(), the same method does not work.
var arrayBlob = e.parameter.arrayBlob;
In the function showList(), the code is assigning a newBlob to the variable arrayBlob. So arrayBlob is available to have the getDataAsString() method used on it.
var arrayBlob = Utilities.newBlob(arrayList);
In the function, submit(), you are trying to pass the arrayBlob blob variable into the submit() function, and reference it with e.parameter.
If you put a Logger.log() statement in the submit() function.
function submit(e){
Logger.log('e: ' + e);
Logger.log('e.parameter` + e.parameter);
var arrayBlob = e.parameter.arrayBlob;
Those Logger.log statements should show something in them. If there is nothing in e.parameter, then there is nothing for the .getDataAsString() to work on.
It looks like you are putting the arrayBlob into a hidden panel.
panel.add(app.createHidden('arrayBlob', arrayBlob));
But when the object is getting passed to the submit(e) function, the arrayBlob might not be getting put into that object.
So, what I'm saying is, the:
Logger.log("arrayBlob #2 = " + arrayBlob.getDataAsString());
Line may be perfectly good, but there is no arrayBlob there to work on. This hasn't fixed your problem, but do you think I'm understanding part of what is going on?
I'm not sure why you are using Blob's here at all, you could simply work with JSON instead.
However, if you have a reason to use Blobs, you can pass the JSON data through your form and create the Blob in your handler, as the modified code below does:
function showList(folderID) {
var folder = DocsList.getFolderById(folderID);
var files = folder.getFiles();
var arrayList = [];
for (var file in files) {
file = files[file];
var thesesName = file.getName();
var thesesId = file.getId();
var thesesDoc = DocumentApp.openById(thesesId);
for (var child = 0; child < thesesDoc.getNumChildren(); child++){
var thesesFirstParagraph = thesesDoc.getChild(child);
var thesesType = thesesFirstParagraph.getText();
if (thesesType != ''){
var newArray = [thesesName, thesesType, thesesId];
arrayList.push(newArray);
break;
}
}
}
arrayList.sort();
var result = UserProperties.getProperty('savedArray');
//get JSON data pass through form.
var arrayBlob = JSON.stringify(arrayList);
var mydoc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setWidth(550).setHeight(450);
var panel = app.createVerticalPanel()
.setId('panel');
//include JSON Data in the form.
panel.add(app.createHidden('arrayBlob', arrayBlob));
var label = app.createLabel("Selecione os itens desejados").setStyleAttribute("fontSize", 18);
app.add(label);
panel.add(app.createHidden('checkbox_total', arrayList.length));
for(var i = 0; i < arrayList.length; i++){
var checkbox = app.createCheckBox().setName('checkbox_isChecked_'+i).setText(arrayList[i][0]);
Logger.log("arrayList[i][0] = " + arrayList[i][0]);
Logger.log("arrayList[i] ====> " + arrayList[i]);
panel.add(checkbox);
}
var handler = app.createServerHandler('submit').addCallbackElement(panel);
panel.add(app.createButton('Submit', handler));
var scroll = app.createScrollPanel().setPixelSize(500, 400);
scroll.add(panel);
app.add(scroll);
mydoc.show(app);
}
function submit(e){
var arrayBlob = Utilities.newBlob(e.parameter.arrayBlob);
Logger.log("arrayBlob #2 = " + arrayBlob.getDataAsString());
// Continues...
}
In the method you were using originally, the Blob itself was never included in the form, you were simply passing the string "Blob" around.
This is because the function createHidden(name, value); expects two strings as parameters, so it calls ".toString()" on the arrayBlob object, which returns the string "Blob".

Google Apps Script Variable Passing

I'm teaching myself Javascript and needed an explanation on old post that I found very helpful. I apologize in advance if this may seem like a sophomoric post on stackoverflow.
I am referencing this post: Google Apps Script Create form with file upload
I have used the script and am trying to learn it because I have high school students who want to create a google webapp to gather data and information for their projects. Of course I have to learn it myself and explain it. There are two sections I am unsure of. Here's the Code.
var submissionSSKey = '0Agd12jO_f4DrdFFYemZvRERvLWQ4UEhENllaWlVwOFE';
var listitems = ['Select a category','Portrait','Landscape','Night shots','Nature','Various']
var schoollist =['Select School','AFNORTH','Baumholder','Bamberg','Lakenheath MS']
var Panelstyle = {'background':'#dddddd','padding':'40px','borderStyle':'ridge','borderWidth':'15PX','borderColor':'#aaaaaa'}
function doGet() {
var app = UiApp.createApplication().setTitle('i14 Art Submission').setStyleAttribute('padding','50PX');
var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400, 200);
var title = app.createHTML('<B>I14 Art Submission</B>').setStyleAttribute('color','grey').setStyleAttribute('fontSize','25PX');
var grid = app.createGrid(7,2).setId('grid');
var list1 = app.createListBox().setName('list1');
for(var i in listitems){list1.addItem(listitems[i])}
var Textbox1 = app.createTextBox().setWidth('150px').setName('TB1');
var schllist = app.createListBox().setName('schllist');
for(var i in schoollist){schllist.addItem(schoollist[i])}
var Textbox2 = app.createTextBox().setWidth('150px').setName('TB2');
var email = app.createTextBox().setWidth('150px').setName('mail');
var upLoad = app.createFileUpload().setName('uploadedFile');
var submitButton = app.createSubmitButton('<B>Submit</B>');
var warning = app.createHTML('Please fill in all fields').setStyleAttribute('background','#bbbbbb').setStyleAttribute('fontSize','20px');
//file upload
var cliHandler2 = app.createClientHandler()
.validateLength(Textbox1, 1, 40).validateNotMatches(list1,'Select a category').validateEmail(email).validateNotMatches(upLoad, 'FileUpload')
.forTargets(submitButton).setEnabled(true)
.forTargets(warning).setHTML('Now you can submit your form').setStyleAttribute('background','#99FF99').setStyleAttribute('fontSize','12px');
//Grid layout of items on form
grid.setWidget(0, 1, title)
.setText(1, 0, 'Category')
.setWidget(1, 1, list1.addClickHandler(cliHandler2))
.setText(2, 0, 'School')
.setWidget(2, 1, schllist.addClickHandler(cliHandler2))
.setText(3, 0, 'Name')
.setWidget(3, 1, Textbox1.addClickHandler(cliHandler2))
.setText(4, 0, 'Email')
.setWidget(4, 1, email)
.setText(5, 0, 'File Upload')
.setWidget(5, 1, upLoad.addChangeHandler(cliHandler2))
.setWidget(6, 0, submitButton)
.setWidget(6, 1, warning);
var cliHandler = app.createClientHandler().forTargets(warning).setHTML('<B>PLEASE WAIT WHILE THE FILE IS UPLOADING<B>').setStyleAttribute('background','yellow');
submitButton.addClickHandler(cliHandler).setEnabled(false);
panel.add(grid);
app.add(panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var ListVal = e.parameter.list1;
var SchoolVal=e.parameter.schllist;
var textVal = e.parameter.TB1;
var Email = e.parameter.mail;
var fileBlob = e.parameter.uploadedFile;
var img = DocsList.createFile(fileBlob);
try{
var folder = DocsList.getFolder('Illuminations 14 Submissions/Art');
}catch(e){DocsList.createFolder('Illuminations 14 Submissions/Art');var folder = DocsList.getFolder('Illuminations 14 Submissions/Art/')}
//var schoolFolder = folder.createFolder(SchoolVal)
img.addToFolder(folder);
img.removeFromFolder(DocsList.getRootFolder())
var sheet = SpreadsheetApp.openById(submissionSSKey).getSheetByName('Art');
var lastRow = sheet.getLastRow();
// var image = sheet.insertImage(img.getUrl(), 4, lastRow+1)
var targetRange = sheet.getRange(lastRow+1, 1, 1, 5).setValues([[SchoolVal,ListVal,textVal,Email,img.getUrl()]]);
//var GDoc = DocumentApp.openByUrl(docurl)
//GDoc.appendTable([['Category : '+ListVal,'Name : '+textVal,'Email : '+Email]])
//var par = GDoc.appendParagraph('IMAGE PREVIEW')
//par.insertInlineImage(1, img.getThumbnail())
//GDoc.appendHorizontalRule();
//GDoc.saveAndClose();
app.add(app.createLabel('Thank you for submitting'));
return app
}
My questions is in function doPost(e), How are the variable declarations able to get values from functio doGet() with a declaration like var ListVal = e.parameter.list1;? Is it the e.parameter? I'm not sure how the e.parameter works. I've got other questions with folder creation, but this is the first step. Thanks in advance for your time.
Radley
The best you can do to clarify your understanding of what is available in the event info object (e in this example) is to visualize it using JSON.stringify().
Simply add a line like Logger.log(JSON.stringify(e)) in the doPost function and look at the Logger after a form submission. You'll see all the e properties that you can retrieve using e.parameter.xxx
here is a view of what you will get : (the file content takes a lot of space but the interesting part is just before it...)
[13-12-06 10:10:27:051 CET] {"queryString":"lib=M_GmTb8T2JCyVLBlttWTHDatIT_UhbT9n&appId=u319190436783&formId=u319190436784&token=AJuLMu1iovLYxDewmZo0Tuv1g2KyC08GJQ:1386320938133&gm1xs=&service=AKfycbymlbEFYZuYIE63cHPT9FlM8WsuWl5fAZFQDdSa9hJ6","parameter":{"gm1xs":"","mail":"testemail#ccc.cc","appId":"u319190436783","lib":"M_GmTb8T2JCyVLBlttWTHDatIT_UhbT9n","list1":"Portrait","token":"AJuLMu1iovLYxDewmZo0Tuv1g2KyC08GJQ:1386320938133","formId":"u319190436784","file":"�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000�\u0000\u0000\u0000�\b\u0002\u0000\u0000\u0000Ada�\u0000\u0000\u0000\tpHYs\u0000\u0000\u000b\u0013\u0000\u0000\u000b\u0013\u0001\u0000��\u0018\u0000\u0000\"liCCPPhotoshop ICC profile\u0000\u0000x��EP\u001e^�����������;�`�\u0000\t.\t�A�\u0006\u000b\u001a\u0002!X \u0010 �[���s��T��V�fn}Ϫ�Y��S��uw5\u0000�{�^^nP,\u0000�=�|t\u0014e���M�\u0010\u0001\u0018 \u00028\u0000\u0000nk[_/i--5���<�\u0000\u0000�,����\u001b�\t����\u0016\u0000�\u0016\u0000�����\u001d\u0000H7\u0000#����\u000f\u0000�%\u0000`*���\u000f\u0000�\u0010\u0000\u0000����\u0004\u0000�O\u0000\u0000��?�\u0011\u0000\u0000����\u0004\u0000\u0018\u0000\u0000�����\u0002\u0000�\u0003\u0000\t����\u0011\u0000T*\u0000\u0000U���\u001f\u0000�R\u0000 �x�9{\u0000��\u0007\u0000�����\u001d\u0000�o\u0000\u0000l��v\u00000�\u0003\u0000�l��<��[N���im��\u001f�?\u0001\u0000\u0000�����kHe�g����a\u000f�������\u0005\u0001\u0000�9�(�\u0000\u0000�\u0000\u0000d�\u0007�\u0000>�\u000b\f\u0001\u0015�\u0007~�\u001a�\u0001O�\u0001<���}�\u001f\u0000\u0000�zz\u0005�8;:�QI{y�ٳQ){�r�Q�pqs���ddlB�Ot�\u0013#\u0000\u0000\u0010\u0002���\"\u0010\u0000��\u0006\u0000�����\t\u0000u�\u0000���G�\u000f\u0000N-\u0000mg��>\u0001�xp\u0000\u0000\u0000\u000fP\u0000&�\u0003Ā\u0002�\u0002&�\u000ex�\u0000\u0010\u0005R#\u001e�\u0000M�\u0007��\u0005�\u0005N�\u001d�#\u0010\u0006�A<H\u0006��[�\u0007�A)�\u0002��\u0019��n�\u0019��q0\u0005~�_`\rl�Cp\u0006��=\u0004\u0002A��Cp!�\u0010J\b=�\u0015�\u0003\u0011�H#�!j\u0010\u001d�1�\n�\b��C� ��dH\u0006$\u000f�\u001eR\ri�tB>C� ӐE�:d\u001fr\u000e�� hP<(9�\u0001�\t\u0015�JCU�zPs�#�\u001b\u001a\u0002���Bs�%�:h\u001b�3t\u001c�\u0003�\u0006=�^�\u0000\f\u0015F\u0000���Ä`�0M�\t�\u0001�\u0003��%��`%�\u0006X\u0017l\u00146\u000b[�\u001d�n�\u0010�p����D����l��\"�R��������f�����������Y�E����\u001d�\u0003����+�[���o�_# \u0010 0\"\b\"(!\u0018#� �\"� \u0014\"|#�G�F�D�BDD$FdE\u0014G�D�F�C�G�E�C�C�A�F�D�ă��d��\u0014���T�ԋ4���t���L�,���l�\u001c���\\�܅�\u001dy\u001b�\u001e\u0005\u001b�\u0011E\u001cE\u000f�\u0005%\u001a%\u0007�\u0001e\u0018e\u0019�\u0002\u0015\u0015�\u0006U\u0018U\u001b�\u00195\n5\u0007�\u0011�\u000b�:�-\u001a\u000e\u001a\u000b�,�\u0019�?Z*Z%Z?�\"�\u0005:::\u0003�\u0014�\t�\u001fz*z5� �*�_\f\\\f\u000e\fe\f;�H�|�6�\u0019�\u0013LdLzLiL\u000b�\u0010�,�\u0016��GX�X\fX�X�X\u0011X�X�X\u000bXWظ��ؚ���)�5�c�{8�8\f8�8v8q8�8�8��0\\Z\\Y\\[�X�2�a�m<\u0004<F<e<\u0017�d�z�I�3|\u001c|>|\u0003� �|�\u001e�5\u0002\u0018\u0001\u0003�2�\u001bA\u001aA3�<�\u001d!9�4�=a\"a\u0003�\f�\r\u0011)�\u0014�=Q\u0012�\u0007�\u001fDw�T��Į�����+$p$,$�$�$E$�$G�x�����I�ͤKdP2\u00162\u001d�P�R�\t�+r\nrEr/�\\�A�#\n\u0002\n)\n\u0017�7\u0014�\u0014�\u0012�Δo(�(\u000f�𩤩ܨr���Ψɨ����SOR��0�����|�Y�E�\u0015�u�}C;#{FGI�N\u0017FWK�D�L/D�D�M?J���`�𒡝a���Q�1���q�\t�I�ɛ��i�\u0019�Y�ٕ��y�\u0005����Ē��\u0015�*���Z�:�\u0006�&���V¶���.�\u001e�^˾�A���\u0011���q�I�i�9�������U���\u001b�[�;����ǖ'�g�\u0017�W�7����\u000f\u001f+�=_\u0011�O~\\~u���\u0003�\u0002�\u0002>\u0002\r\u0002�t�V�\u0005�\u000bBxBZB)B_��e�#���oE\u0004D�D�ENE�E]EkD��\u0018�����6�iĭ�ߋ�IPIXI��X�����,�ܐ������ڕf�v���>���i���\u0015�\r�헃�)�%�M������ɯ*�(8*�*�)�+�*�+�+�*�+-(�+�*W+��\b���\f�����n����u�C�U�3՗5�5<4�5���f��\u0016����'m\u0004m-�|�\u001d\u001dn�0�Q]\\]K�\u001a�k=\u0019�4�_�L���\u0003\u0006�\u0006f\u0006�\u00067�r�\u0019�kF�F�F��$���\u001d&�&\u0006&\u0015&W��oM��������\u0019̓��,H,�,z,1-�-[��\f�j�\u001e�5�K��l�m\nl�lem�m\u000f�����ۋ�g��:�;d8�9�;f:�;I:e9\u001d9�:�9�qQr)v�q�t�t}v3t����n������1�I�\u0019�9���\u0015��-�����Gէ�\u0017�k������7�����=#\" ?�o�A`K\u0010v�G�D0Kpb�n�BHy(\\�m�#\u0018uXt�z�t��\bH�M�#$md\\�v�bTU4J�k��\u0018�����X�خ8򸨸�\u0017�/j�1�}�\u0017^��,N�KpN�L�M�M|J�K�̕���b���\u0015���Wϩ\u000e��i\u0002iE�\u0011^{��O�L����\b���T�l{C�&���[˷cY|Y��(���k9j9\u001d�t��s\u001f��~���( +H,�)�+�)�*j(&/N.�{����{��m%\f%Y�\b�\u0001�;e\u0006e��B��\u0015$\u0015�\u0015��\u001e�kU:UCՂ��5d5i��Z���:���z��\u0006���\u001f\b>$7�F�ƃ&���f��\u0016�����\u001f\u000bZq[�� m�mg�N�k\u001d�\u001dӝ*�\u0003]�]��8>UvSw����������>���]�{�\u001f}v�9`9�k�hpnH{hrXu�ˈ����h�\u0017�/�c\"c�_����\u000b��M�O�~���:)0��]�{ǔ�T״�t����Y�ّ9��\u001f\u001a?����.�-�����g)`��W�2�r�\n�J�*�j�o��\u001f�\u0004�z���'6t7~m�n\u001en�n=l���d�R�V���u�+�O\u001d�\u001el\u001fz\u001d�\u001f�\u001fc\u001f\u0017�0�|<�:�83:������<����r�J�j�����&�/�ߪ[���;û���\u0007ć�G�Ǯ'է�g��g/k\u001fk\u0000�?m%��\u0001��J\u0000Ѝ\u0001��\u0002\u0000���~�_�A\u0000�\u0002\u0000�A)��\u0018Bڡ��#�/�\f�\u001a\u000e\u000f.\fn\u000f^\u000f�\u0017�\u001d�\u0000\u0011\r1\u0014�\u0010�\u0002i\u0006Y\u0001�\u0007�\u0017�\u001a�\u0016�\u0000�\b-\u0013\u001d\u0013=\u0015\u0003\u0003�\u0015&\u0016f&\u0016\t�;l&�\u0016\u001cq�q\\\u0013�C�\b|<�Z\u0002\u0005�u�H\"j�!b7\u0012\u0002�AR_2F�U�<\nCJR�u�\u001a� \u001aeZ\n�\u001b�\u0019�\u000f\fi�\u001eL\u001a�\u001c,�,���l3�\u001c]��\\-�m<=�_����\u0005��\b��E4D�Œū%�$K]ˠ�\u0012�Q�3(�(�+q(s�������3j�jRj�j\u0013�`��!�C��\fn\r��΍�L�M�͎̏-�,/��l��hvD�\f\u000eB�jN���.E���\u0016�/=��ؽU|\u001c|c��\u0003~\u0006^\u0005�p�����'DTD\u000eFm�#b��$_X�G�|��9q3\u0019>��j�gZ����L�7�ou�B��s����3\u0014�\u0016F\u00175\u0016���.�+\r,�)_�ĩR�\u000e�i�ݫ�l0��8�\fi\u0011�\u0018���v�����U�鸇�ק���q#~0uhq�~����W�q牾I��>S�g8g��N�5\u0017>,b.y��Z�Y}������\u0016���]����P������\u001f���K�����[ڻ�'����f��R�Q�Q�Q�V����d�b�fСե�#�'6 4�3�1�2�0E7C3ǰ��Ķ·&���e��\u0017sPv4rrq�t�t�t����c���\u001b��ȗ�O�_-�,�=(\"8-�8�)�s�l�V�u4R\fI,{��\u000b�xǗa\t鉕I��?RNR\u0011�h^��\u001bg\u0004ff�i����C����_T0Qx_����}^�l\u0019Z�RE\\�#5�F�6�n�\u0001��vcN�z\u000b�ǀ��v�\u000e�ΦO�n���>H����A�!��Q�/�c+�\u0012\u0013�&��\u001d��g�g����\u0016�\u0017Y�^��Z1[\u001d\\c]���=�+��z�xXp�w�z����\u0005�e�5�Mϭ���C�����)�+������1��hPh\u0012k�jc� �Bu\u001f����\u0018\u001c\u0019�\u001am\u0018�6Y1]6�e�l��r�������\u000eŞԁ�Q���9ƥ�u�m�\u0003ٓ�K���'���߂�] y�T�]HBh]�T�U$I�d�}LrlS��\f\t��IEɣ)���i����s2\u00063Oޒf)f��ϝ�{(`-4)J(�x�WB\\�R\u0016Z^[�\\�V-^�^[X7Y��Ѻ)�y�底�ͼ=�c���\u0013o�kOY��~�φ\u0003Y���D#f�%_���GOLM�~\u000f����M�ۛ�_(Y\u0004K濺WHWC/�Kl�n!m{�,�)�\u001d�\u001c\u0015�\u0010���!=/��\u001a�����kyp}�x~\u0006���\u0002\u0000\u0000\u0010\t\u0000P\u0001\u00000�\u0007#I\n�<)\u0000�\u0000�\u0001\u0000hI\u0001�'\u0005 /l\u0001$�\t#��\u0001\f�\u001f~\u0000\u0000\u0001P\u0000\u0007\u0010\u00002#\u0003X��=�\u0000\u000b�\u0002B#\u0012(\u0002-`\fl�\u001b\b\u00041�\u0015�\u0005�\u0019�o�\u00178\u0000�\u0010$\b\u0011�\t\"\fQ��B�!Q�\fH\u0005�\u0013�\r�\u000e���B��\u0002P5�-4\u0004�\u000e���CB��P`�01�\u0001�\u000b�\u0004+����`�p�p�p�p�p1p�p�p�p��x�<�Z�\u001e�)��c�{\b�\b\f\b\n\b�\bq\be\bC\b[�p�t�r�v�/\u0010�\u0011G\u0010w�\u0010�\u0018�������j�&���1�9�����3�[� _�\u0010�\b�\u0018���\u0014�����<�R�ʠڢơ�����!���������5�M�����\u001b�\u0007��B_A ��ÈǨ��q���Ƀ��\u0019���ً��\u0005�Ō����\u0006�\u0003k\u0019\u001b`�b+b�b�a�`/`��P���8�$�4���\\�\u0012��Z���Ɲ�=���\u0013�3ŋ�+�\u001b�;�������\u000f�/����$#$`%� �!�\"�$X!\u0004�t�J���i�-��wD\u0014D2D�D�D�D�DW�������/���'��I\bIDI�H�H�I&I.H�H�ImI\u0013H\u001bHgIo�(�\u0014���2�:���\u0011�9�\r�#�+�'�o(()�(|(�)�)N)I(�(=)�)G)/�(�Ԩ��*�f�!�\u001c�f�IԝԻ4\u00044r4�4�43�PZnZk�t�\u0001�s:Z:=�\u0017tmt��������\u001f��\u0019�\u0018\u0014\u0018�\u0019�\u0018~3�2*0�060n0\u00110�2E2}d�g�`�eN`�e�daf�dy�2�\ne\u0015f�b�d]e�gSc�c��v���n˞�>ˁ�!�\u0011���q���i͙�9DžΥ�\u0015���늛�ۙ��{���G�'��\u000b/�W�7�������ϑ��o���_�?�B\u0000I#N J�[� ���`��\u0010���P�В0����k�\t\u0011d\u0011y�\u0018�^�{QAQ_�F�#1f1{�\u0012�Uq\u0012qC�L��\u0012�\u0012J\u0012q\u0012�\u0012\u000f�B���\u001f$\u000f�\u0018�l�����\t�u�Ӥ'd�d�ebd�d\u001ed�e\u0003e?ʞ�q�y���\u001d�3�;ȗ�o*�(X+�S�H�h�X���D�d�T���L�l�\\���B�b��Ne]�F�N�\\uG�I�E�N�D�K�G��F�F�&DSN��\u0016����[�Em2m+�2�=\u001d6\u001do�V�;]\t�X�/z�z:z�z+�4����\u0017\u0006�\u0006�\u0006Æ��چن�FtF�F�F��R�/�'M�M�M�L�LyMCM\u0007�P�t��Ͷ�����{,\u0010,4,�-�,�-},���4�r�6�Y���l�mtm\nmvmyl�lG����*�����\u0013�g\u001d(\u001c�\u001dZ\u0

How to retrieve sharepoint 2013 list data using JQuery or JavaScript and Fill DropDownList?

I am trying to retrieve list data using JavaScript. But something goes wrong. I am trying to debug the code but I am not able to understand that thing.
Following is the JavaScript Code:
ExecuteOrDelayUntilScriptLoaded(PopulateDepartments, "sp.js");
var _ctx = null;
var _web = null;
var _allItems = null;
function PopulateDepartments() {
debugger;
_ctx = SP.ClientContext.get_current();
_web = _ctx.get_web();
var list = _web.get_lists().getByTitle("ServiceType");
var query = new SP.CamlQuery();
query.set_viewXml("<View><Query><OrderBy><FieldRef Name='Title'/></OrderBy></Query></View>");
_allItems = list.getItems(query);
_ctx.load(_allItems, 'Include(Title,ID)');
debugger;
_ctx.executeQueryAsync(Function.createDelegate(this, this.PopulateDepartmentSuccess),
Function.createDelegate(this, this.PopulateDepartmentFaild));
}
function PopulateDepartmentSuccess() {
var ddlEntry = this.document.getElementById("ddl1");
ddlEntry.options.length = 0;
var listEnumerator = _allItems.getEnumerator();
while (listEnumerator.moveNext()) {
var currentItem = listEnumerator.get_current();
ddlEntry.options[ddlEntry.options.length] = new Option(currentItem.get_item("Title"), currentItem.get_item("ID"));
}
}
function PopulateDepartmentFaild() {
alert("Something went Wrong....!!");
}
Whenever I run this code it shows me alert box.
Please Help..
There are times when this doesn't takes the correct reference.Check if it works with removing this reference .so Instead of this
_ctx.executeQueryAsync(Function.createDelegate(this, this.PopulateDepartmentSuccess),
Function.createDelegate(this, this.PopulateDepartmentFaild));
try using something like this
_ctx.executeQueryAsync(PopulateDepartmentSuccess,PopulateDepartmentFaild);
I think.If your Creating Sharepoint App, it is necessary to give permissions to web in AppManifest.xml.

Categories

Resources