0

I am using the client side object model to approve multiple items from the form library. I need to access the values of some of the columns of the form library. The following is my code:

      var context;
       var web;
       var itemCount;
       var count = 0 ;
       SP.UI.Notify.addNotification('Approving item(s)...');
       approveItems();
       function approveItems ()
       {     
         alert('testttt');
         context = SP.ClientContext.get_current();
         web = context.get_web();
         context.load(web);
         var currentLibId = SP.ListOperation.Selection.getSelectedList();
         var currentLib = web.get_lists().getById(currentLibId);          

          // Get all the items in the list
          employees = currentLib.getItems(); 
          alert('employees:'+employees);
          // Load the web in the context and retrieve only selected columns to improve performance 
          context.load(this.employees, 'Include(ID,FirstName)');              
          alert('after load.');
          context.executeQueryAsync(get_Employees_onSuccess,get_Employees_onFailure);               
          alert('after...');
       }  

        function get_Employees_onSuccess() {
           // Get the collection
           alert('inside success..');
           var employeeCollection = this.employees.getEnumerator();          
           alert('employeeCollection' +employeeCollection);
           while (employeeCollection.moveNext()) {
              var employee = employeeCollection.get_current();
              alert('id: ' +employee.get_item('ID'));
              alert('FirstName: ' + employee.get_item('FirstName'));              
           } 
        }
        function get_Employees_onFailure() {
           alert('An error occurred while fetching data. Please contact your system administrator.');
        }

When I deploy the solution and test, the alert of the onFailure is displayed. I am not able to figure out the reason why the code in onSuccess is not executing.

Please guide.

2

You can debug your app with error handling like this:

function onFailure(sender, args) {
    ULS.enable = true;
    ULSOnError(args.get_message(), document.location.href, 0);
    //if debugging
    alert(args.get_message());
}
  • Where can I see the logs? In the ULS Log viewer? – Mancy Desaee Sep 9 '13 at 8:48
0

getItems takes SP.CamlQuery object as parameter. If you need all items use ID > 0. Forexample:

camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
        '<Value Type=\'Number\'>1</Value></Geq></Where></Query>

SOURCE

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.