unable to get property ‘getenumerator’ of undefined or null reference SharePoint

sharepoint 2013 javascript insert item with lookup field
SharePoint deveopment training course

This SharePoint tutorial explains, how to resolve Unable to get property getenumerator of undefined or null reference issue in jsom SharePoint 2013/2016/Online.

As part of my project, I need to retrieve or read the lookup field value using ECMA script block in SharePoint 2013/2016/Online. When I try to do it I got the below error message.

unable to get property 'getenumerator' of undefined or null reference
unable to get property ‘getenumerator’ of undefined or null reference
unable to get property 'getenumerator' of undefined or null reference sharepoint
unable to get property ‘getenumerator’ of undefined or null reference sharepoint

I was trying to set the lookup value with the below code:

var strTxtFiled = "";
var ObjLstEnum = this.allItems.getEnumerator();
while(ObjLstEnum.moveNext())
{
       var objCrrItem = ObjLstEnum.get_current();
     strTxtFiled += objCrrItem.get_item('Title') + '-' +objCrrItem.get_item('CompanyName').Value + '\n';
}

Note: This works for a normal field but for a Lookup Field it will not work.

unable to get property ‘getenumerator’ of undefined or null reference sharepoint

We must have to read the lookup field value with get_lookupValue() method.

The code snippet will be like as below:

strTxtFiled += objCrrItem.get_item('Title') + '-' +objCrrItem.get_item('CompanyName').get_lookupValue() + '\n';

The complete code will be like as below:

function fnGetLkpValue()
{
    var objClntContext = new SP.ClientContext.get_current();
    var objWeb = objClntContext.get_web();
    var ObjLst = objWeb.get_lists().getByTitle("Car Inventory");
    var query = SP.CamlQuery.createAllItemsQuery();
    allItems =ObjLst.getItems(query);
    objClntContext.load(allItems, "Include(Title,CompanyName)");
    objClntContext.executeQueryAsync(Function.createDelegate(this, this.fnSccGetVal), Function.createDelegate(this, this.fnFailGetVal));
}
function fnSccGetVal() {
    var strTxtFiled = "";
    var ObjLstEnum = this.allItems.getEnumerator();
    while(ObjLstEnum.moveNext())
    {
        var objCrrItem = ObjLstEnum.get_current();
        strTxtFiled += objCrrItem.get_item('Title') + '-' +objCrrItem.get_item('CompanyName').get_lookupValue() + '\n';
    }
    alert(strTxtFiled);
}
function fnFailGetVal(sender, args) {
    alert("fnFailGetVal. Message:" + args.get_message());
}

Little background/prerequisites to execute this script:

  • Create 2 lists
  • Primary List
  • Car Inventory
  • Create lookup field from car inventory list to primary list

With this code operation completed successfully.

unable to get property 'getenumerator' of undefined or null reference sharepoint
unable to get property ‘getenumerator’ of undefined or null reference sharepoint
unable to get property 'getenumerator' of undefined or null reference sharepoint online
unable to get property ‘getenumerator’ of undefined or null reference sharepoint online
unable to get property 'getenumerator' of undefined or null reference sharepoint 2013
unable to get property ‘getenumerator’ of undefined or null reference sharepoint 2013

You may ECMA script tutorials:

Hope this SharePoint tutorial explains how to solve Unable to get property getenumerator of undefined or null reference in ECMA Scripting.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Krishna Vandanapu

I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019

View all posts by Krishna Vandanapu →