0

I have a custom js that creates dynamic layout. There is a function which renders this layout consisting of multiple divs. When I debug the JS, the layout is rendered correctly but when I run it without debugging the code does not execute.

It also gives the error "The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.". I am not able to figure out what is the issue.

The function that is being called is complex. Is there any mechanism to set the delay in the execution of the JavaScript?

Please guide.

Code as given below:

    var documentType;
    var docLibName = "Documents";
    var documentTitles;
    var SiteCol_URL = window.location.protocol + '//' + window.location.host;

    $(document).ready(function(){


    //Custom code to get documents based on query:
    SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function () {

      var serviceOffering = getQueryStringParameter("sf"); 
        serviceOffering = decodeURIComponent(serviceOffering);  
        var docTypeArray = new Array(6);
        docTypeArray = ["Framework Documents","Case Studies","Presentations","Others","Customer Literature","Pricing"]      

        for(var i =0; i<5;i++)
        {
            documentType = docTypeArray[i];
           retrieveListItemsInclude(serviceOffering, documentType,docLibName);
            wait(2000);
        }

});
3
  • 1
    It will help if you can share the code. Feb 5 '15 at 6:00
  • You haven't included retrieveListItemsInclude. It is this function where error may be showing up. Feb 5 '15 at 6:44
  • In place of wait you can use setTimeout(function (){ //something you want delayed }, 5000); // how long do you want the delay to be?
    – Amit
    Feb 5 '15 at 6:49
0

I had a very similar problem recently when working with AngularJS in SP 2010. I assume the retrieveListItemsInclude method is where your JSOM code can be found.

Should be really a timing issue. In my case I was able to see that the JSOM request was sent to the server and it responded with the expected results, but JSOM was simply not able to process it. I suggest you to monitor the network traffic using Fiddler to find out more on the issue.

You should try either:

setTimeout(function () {
      retrieveListItemsInclude(serviceOffering, documentType,docLibName);
    }, 5000); // you can play with the timeout value, increase / decrease it depending on the results you experience

or

$(document).ready(function(){
  setTimeout(function () {
          startQueries();
        }, 5000); // you can play with the timeout value, increase / decrease it depending on the results you experience
});

where startQueries encaplsulates your current ustom code that should get documents based on your query

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.