Unable to get property getEnumertor of undefined or null reference in ECMA Scripting Get or retrieve Lookup Field value

sharepoint 2013 javascript insert item with lookup field
InfoPath alternatives for form designing SharePoint

Here we will discuss how to resolve Unable to get property getEnumertor of undefined or null reference issue in jsom SharePoint 2013.

Issue:
As part of my project I need to retrieve or read the lookup field value using ECMA script block in SharePoint 2013. When I try to do it I got the below error message.
sharepoint 2013 javascript insert item with lookup field
sharepoint 2013 javascript insert item with lookup field
set lookup column value sharepoint 2013 json
set lookup column value sharepoint 2013 json



Issue:
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.

Solution to resolve Unable to get property getEnumertor of undefined or null reference error:

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.
sharepoint 2013 set lookup field value javascript
sharepoint 2013 set lookup field value javascript
sharepoint 2013 javascript insert item with lookup field
sharepoint 2013 javascript insert item with lookup field
sharepoint 2013 javascript insert item with lookup field Tutorial
sharepoint 2013 javascript insert item with lookup field Tutorial

Hope this helps!!!!

Similar SharePoint 2013 Tutorials

About Krishna Vandanapu

I am Krishna.Vandanapu a SharePoint architect working in IT from last 12 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 →

Leave a Reply