Question

The below code is working fine in chrome but not working for IE.

    var clientContext = new SP.ClientContext(siteURL);
    var oList =clientContext.get_web().get_lists().getByTitle('MasterNotification');
    var newItem = new SP.ListItemCreationInformation();
    this.item = oList.addItem(newItem);
    item.set_item("NotificationNumber",WONumber);

It's giving below error:

SCRIPT438: Object doesn't support property or method 'set_item'

Était-ce utile?

La solution

You have created item by using "this" object, so while accessing also you need to use "this". change this

item.set_item("NotificationNumber",WONumber);

to

this.item.set_item("NotificationNumber",WONumber);

or just delete "this". and use var

var item = oList.addItem(newItem);
item.set_item("NotificationNumber",WONumber);

if you want to use the same 'item' variable in other functions call the other function with this parameter in your success callback. you cannot execute the other function without calling this function. So change your code to use callbacks or you can use jQuery differed Objects to manage the async calls(but it will be confusing for the beginners). change the executeQueryAsync as follows.

    clientContext.executeQueryAsync(function(){
    //call the other function with parameter
     myOtherFunction(item);
    }), function(s,a){alert(a.get_message())});


    function myOtherFunction(item){

    }

the cleaner way is using deferred object or call your function with callbacks like

   function createItem(successcallback,failcallback){
    //...code to create item
     clientContext.executeQueryAsync(function(){
       successcallback(item);
     },function(s,a){
       failcallback(a.get_message())});
   }

   function functionUsingItem(item){
    //
   }

   function functionToShowError(errMsg){
    //
   }

call the createItem method like

createItem(functionUsingItem,functionToShowError);
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top