Skip to main content
replaced http://sharepoint.stackexchange.com/ with https://sharepoint.stackexchange.com/
Source Link

I found this question titled How to return a value using context.executeQueryAsync?How to return a value using context.executeQueryAsync?, which outlines a callback method. But when I implemented that, it didn't really solve anything for me. I still couldn't seem to return the value from anywhere or get it to act synchronously.

I found this question titled How to return a value using context.executeQueryAsync?, which outlines a callback method. But when I implemented that, it didn't really solve anything for me. I still couldn't seem to return the value from anywhere or get it to act synchronously.

I found this question titled How to return a value using context.executeQueryAsync?, which outlines a callback method. But when I implemented that, it didn't really solve anything for me. I still couldn't seem to return the value from anywhere or get it to act synchronously.

added 360 characters in body
Source Link

Essentially now I can do:

    $(document).ready(function () {
        getList("mySPList", sharePointReady);
    });

    function sharePointReady(list) {
       // carry on having sorta asynchronously loaded it
       // and now I can use one function for each page
       // without like 5 global variables
    }

Essentially now I can do:

    $(document).ready(function () {
        getList("mySPList", sharePointReady);
    });

    function sharePointReady(list) {
       // carry on having sorta asynchronously loaded it
       // and now I can use one function for each page
       // without like 5 global variables
    }
added 1020 characters in body
Source Link

Edit:

One thing that I've decided sort of works. Is passing a function as a parameter to getList that you want it to go to when successful. That way you can call

 getList("list1", functionForList1)
 getList("list2", functionForList2)

 function functionforList1(list){
    // do stuff
 }

 function functionforList2(list){
    // do *other* stuff
 }

function getList(listName, goToFunction) {

    var get = function (callback) {

        // blahblahblah

        currentcontext.executeQueryAsync(function () {
            callback(null, listItemCollection);

        }, function (a, b) {
            callback(new Error(b.get_message()));
        });
    };

    get(function (error, listItemCollection) {
        if (error) {
            alert(console.error(error));
            return;
        }

        goToFunction(listItemCollection);
    });
}     

Edit:

One thing that I've decided sort of works. Is passing a function as a parameter to getList that you want it to go to when successful. That way you can call

 getList("list1", functionForList1)
 getList("list2", functionForList2)

 function functionforList1(list){
    // do stuff
 }

 function functionforList2(list){
    // do *other* stuff
 }

function getList(listName, goToFunction) {

    var get = function (callback) {

        // blahblahblah

        currentcontext.executeQueryAsync(function () {
            callback(null, listItemCollection);

        }, function (a, b) {
            callback(new Error(b.get_message()));
        });
    };

    get(function (error, listItemCollection) {
        if (error) {
            alert(console.error(error));
            return;
        }

        goToFunction(listItemCollection);
    });
}     
added 132 characters in body
Source Link
Loading
Source Link
Loading