Aug 24 2016
06:21 AM
- last edited on
Feb 10 2023
01:44 PM
by
TechCommunityAP
Aug 24 2016
06:21 AM
- last edited on
Feb 10 2023
01:44 PM
by
TechCommunityAP
Hello,
This is my first post @network.office.com.Hope this is not gonna ignored.
I'm just trying to get some value and append it to a list when everytime when a asyncronous call of code.
Example:
function prepareTables() {
getItemsWithCaml('CustomMyList',
function (camlItems) {
var listItemEnumerator = camlItems.getEnumerator();
while (listItemEnumerator.moveNext()) {
var listItem = listItemEnumerator.get_current();
alert(listItem.get_item('Email'));
}
alert('Completed table prparation.');
},
function (sender, args) {
alert('An error occured while retrieving list items:' + args.get_message());
});
}
function getItemsWithCaml(listTitle, success, error) {
var clientContext = new SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getByTitle(listTitle);
var camlQuery = new SP.CamlQuery();
var camlItems = list.getItems(camlQuery);
clientContext.load(camlItems);
for(var i=0;i<3;i++){
var a ='#';
clientContext.executeQueryAsync(
function () {
success(camlItems);
},
error
);
}
};
prepareTables();
I want to append value of a 3 time in alert(listItem.get_item('Email'));.
Means every time we get a value from list it append with # but our value is in getItemsWithCaml function.
Help Needed!
Thanks.
Aug 24 2016 06:39 AM
It's pretty hard to understand what you are trying to achieve.
What it looks like you are doing is executing the call to SharePoint three times and then iterating over the result three times. That's a bit weird as the call wil retreive the same results.
clientContext.load(camlItems); for (var i = 0; i < 3; i++) { var a = '#'; clientContext.executeQueryAsync( function () { success(camlItems); }, error ); }
Aug 25 2016 09:26 PM
I want a function call back behaviour (like deferred and promises).
I have my values just before Async function.
I want to concatenate each value every time with SharePoint list data when I get a value.
Aug 26 2016 12:41 AM
This blogpost has a great example and explanation on using promises with JSOM.
http://blog.qumsieh.ca/2013/10/31/using-jquery-promises-deferreds-with-sharepoint-2013-jsom/