2

Hi I have the following code, how can I pass oList into function onQuerySucceeded?

function lockMandaysItems(tID,oList) {

    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle(oList);

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'TeamRequest\'/>' + 
        '<Value Type=\'Number\'>'+ tID +'</Value></Eq></Where></Query></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        

}

function onQuerySucceeded(sender, args) {
}
0

Added in 1st function: this.myParam = "Hello SharePoint World";

then available in called function

0

I believe you are trying to do what I have done in below code.

<script>
    var listItemInfo = '';
    ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");

    function retrieveListItems() {
        retrieveSingleList('/sites/xxx/yyy', 'mylist');
        retrieveSingleList('/sites/xxx/zzz', 'mylist');
    }

    function retrieveSingleList(siteURL, listName) {
        var clientContext = new SP.ClientContext(siteURL);
        var oList = clientContext.get_web().get_lists().getByTitle(listName);
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' +
            '<Value Type=\'Number\'>1</Value></Geq></Where></Query></View>');
        this.collListItem = oList.getItems(camlQuery);
        clientContext.load(collListItem);
        var mySuccessCallBack = Function.createCallback(onQuerySucceeded, this.collListItem);
        clientContext.executeQueryAsync(Function.createDelegate(this, mySuccessCallBack), Function.createDelegate(this, this.onQueryFailed));
    }

    function onQuerySucceeded(sender, args, PcollListItem) {
        var listItemEnumerator = PcollListItem.getEnumerator();
        listItemInfo += '<table border=1><tr><td>ID</td><td>Title</td><td>Likelihood</td><td>Event</td></tr>';
        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            listItemInfo += '<tr><td>' + oListItem.get_id() +
                '</td><td>' + oListItem.get_item('Title') +
                '</td><td>' + oListItem.get_item('Likelihood') +
                '</td><td>' + oListItem.get_item('Event');
            listItemInfo += '</td></tr>';
        }
        listItemInfo += '</table>';
        document.getElementById("RollupPlaceHolder1").innerHTML = listItemInfo.toString();
    }

    function onQueryFailed(sender, args) {
        document.getElementById("RollupPlaceHolder1").innerHTML = ('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
</script>
-1

You need to make 2 changes

1. Change the definition of onQuerySucceeded function to contain your variable oList.

2. Change the way you call this success function.

Refer below the updated code.

function lockMandaysItems(tID,oList) {

    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle(oList);

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'TeamRequest\'/>' + 
        '<Value Type=\'Number\'>'+ tID +'</Value></Eq></Where></Query></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function () { onQuerySucceeded(oList); }, queryFail);        

}

function onQuerySucceeded(oList) {
}

function queryFail() {
}
  • The code doesnt work. Are you sure sender, args need to be omitted? – Raj Chahal May 15 '15 at 12:08
  • What problem are you facing? I have updated answer for queryFail function, may be this was a problem. Also as far as my experience is concerned removing sender and args do not cause a problem unless you use it inside a function or pass values from somewhere else. – Asad Refai May 15 '15 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.