Home

Synchronous programming behavior with JSOM in SharePoint Online ?

Vipin Tyagi
Contributor

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.

 

3 Replies

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
        );
    }

 

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.

 

Related Conversations
Sharing an excel sheet public link
shunde3 in Microsoft Teams on
6 Replies
Reporting on Project Online (PWA) Timesheets
Andy Dennis in Project on
3 Replies
Adding a user or sending download link
Scott Mackay in Office 365 on
8 Replies
Cutomizing SharePoint Online Modern Page
Vikas Dhingra in SharePoint on
4 Replies