While Updating list item, gets error as Error: Unable to get property 'set_item' of undefined or null reference

Hi All,

Please help me as I am stuck on this.

I have a javascript written on library edit form.

When I try to update list items of other list, I get the error as:-

Error: Unable to get property 'set_item' of undefined or null reference.

Please help me as I am not able to proceed further.

Your help is highly appreciated.

Thanks & regards,

Manish

August 19th, 2015 11:04am

Hi Manish,

As it is hard to solve the issue without knowing the code, could you please provide the code here for further research?

You can use F12 tool to debug the code to see if the property set_item is defined or not in the code.

Best regards,

Victoria

Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 9:02am

Hi Victoria,

Below is the code for your reference.

var LibID=GetUrlKeyValue("ID");
    var clientContext = new SP.ClientContext.get_current();
   var oList = clientContextInProcess.get_web().get_lists().getByTitle(ListName);
   var camlQuery = new SP.CamlQuery();   
    var strQuery = "<View>><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>"+LibID+"</Value></Eq></Where><OrderBy><FieldRef Name='Title' Ascending='TRUE' /></OrderBy><ViewFields><FieldRef Name='Title' /></ViewFields></Query></View>";
    camlQuery.set_viewXml(strQuery);
    this.collListItem = oList.getItems(strQuery);
    clientContext.load(collListItem);   

    var listItemEnumUpdateInProcess = collListItem.getEnumerator();
    while (listItemEnumUpdateInProcess.moveNext()) {
    var oListItemID =listItemEnumerator.get_current();
    oListItemID.set_Listitem(Title, LibID);
    oListItemID.update();
    clientContext.load(oListItemID); 
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

Sometimes the error is at clientCOntext.Load or at getEnumarator or sometines at set_ListItem.

Please help me as I am stuck on this.

Thanks & regards,

Manish

August 26th, 2015 4:05am

Hi Manish,

There are some logical errors in your code.

Here is an code example for your reference:

	var LibID=GetUrlKeyValue("ID");
	var clientContext;
        ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "SP.js"); 
	function retrieveListItems() {
     	clientContext = new SP.ClientContext.get_current();
    	var oList = clientContext.get_web().get_lists().getByTitle('ListName');	
    	var camlQuery = new SP.CamlQuery();    
     	var strQuery = "<View>><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>"+LibID+"</Value></Eq></Where><OrderBy><FieldRef Name='Title' Ascending='TRUE' /></OrderBy><ViewFields><FieldRef Name='Title' /></ViewFields></Query></View>";
    	camlQuery.set_viewXml(strQuery);
    	this.collListItem = oList.getItems(camlQuery);
    	clientContext.load(collListItem);  
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        
	} 
 
	function onQuerySucceeded(sender, args) {
		var listItemEnumUpdateInProcess = collListItem.getEnumerator();
     	        while (listItemEnumUpdateInProcess.moveNext()) {
     		var oListItemID =listItemEnumUpdateInProcess.get_current();
     		oListItemID.set_item('FieldNeedToBeUpdated', LibID);
     		oListItemID.update();
     		clientContext.executeQueryAsync(Function.createDelegate(this, this.on_myUpdate_Success), Function.createDelegate(this, this.on_myUpdate_Failure));
     	        }   	
	}

	function onQueryFailed(sender, args) {
    	         alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
	}
	
	function on_myUpdate_Success() {
    	         alert('Item updated!');
	}

	function on_myUpdate_Failure(sender, args) {
    	         alert('Update failed. ' + args.get_message() + '\n' + args.get_stackTrace());
	}

Best regards,

Victoria

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 2:10am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics