Skip to main content
edited
Source Link
Amal Hashim
  • 28.4k
  • 5
  • 32
  • 61

Let's take for example the code below:

function createListItemProdus() {
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('achizitii_produs');
             
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('name', some_value);
            
    oListItem.update();
     
    clientContext.load(oListItem);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceededGol), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

From what I've read on the Internet, the load function loads the content of the list from the server to the client.

Then why do I use clientContext.load(oListItem); after oListItem.set_item?

I am using Sharepoint 2013.

Let's take for example the code below:

function createListItemProdus() {
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('achizitii_produs');
         
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('name', some_value);
        
    oListItem.update();
 
    clientContext.load(oListItem);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceededGol), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

From what I've read on the Internet, the load function loads the content of the list from the server to the client.

Then why do I use clientContext.load(oListItem); after oListItem.set_item?

I am using Sharepoint 2013.

Let's take for example the code below:

function createListItemProdus() {
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('achizitii_produs');            
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('name', some_value);           
    oListItem.update();    
    clientContext.load(oListItem);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceededGol), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

From what I've read on the Internet, the load function loads the content of the list from the server to the client.

Then why do I use clientContext.load(oListItem); after oListItem.set_item?

Source Link
bloomingsmilez
  • 567
  • 6
  • 14
  • 29

Why do I use load AFTER these portions of code?

Let's take for example the code below:

function createListItemProdus() {
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('achizitii_produs');
        
    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('name', some_value);
       
    oListItem.update();

    clientContext.load(oListItem);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceededGol), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

From what I've read on the Internet, the load function loads the content of the list from the server to the client.

Then why do I use clientContext.load(oListItem); after oListItem.set_item?

I am using Sharepoint 2013.