I have a list with around 1000 columns and I need to be a able to prepopulate another field with a lookupid of another lookup field on the same list

I am getting error when I use:

var LookUpColumnId = oListItem.get_item('LookUpColumn').get_lookupId();


Uncaught Error: The property or field has not been initialized. It has not been requested or the request has not been executed.

See snippet below:

function onUpdateSucceeded() {

    var itemEnumerator = items.getEnumerator();
    while (itemEnumerator.moveNext()) {
        var item = itemEnumerator.get_current();
        // You now have the item you were looking for!

    var siteUrl = '/sites/Dev/'; 
    var clientContext = new SP.ClientContext(siteUrl);
    oList = clientContext.get_web().get_lists().getByTitle('Test');

    var itemsToLoadForUpdate = Array(); // Holds our "current" items to update
    var totalItemsToUpdate = 900;
    var limitItemsToUpdate = 50; // Update every 90 items

    var batchUpdatesCounter = Math.ceil(totalItemsToUpdate / limitItemsToUpdate); // If you need to count the remaining batch updates
    var restItemsToUpdate = 0; // Items to update after (see below)

    for (var i = 0; i < IDs.length; i++) {
        var oListItem = oList.getItemById(IDs[i]);

        /* Newly addedd get lookup id of items*/

        //var lookupFieldValue = oListItem.get_item('LookUpColumn');
        //var lookupId = lookupFieldValue.get_lookupId();


        //This works but when i set the lookupId above it doesn't i can;t even get the lookupId 
        oListItem.set_item('LookUpID', 1);

        itemsToLoadForUpdate[i] = oListItem;

        if (i && i % limitItemsToUpdate == 0) {
            console.log('Updating ' + limitItemsToUpdate + ' items...');
            clientContext.executeQueryAsync(this.onUpdateSucceeded, this.onUpdateFailed);
            restItemsToUpdate = 0;
        else { // Remaining items to update
            restItemsToUpdate = i % limitItemsToUpdate;


    if (restItemsToUpdate) {
        //console.log('Updating rest items...');
        console.log('Updating ' + restItemsToUpdate + ' items...');

        clientContext.executeQueryAsync(this.onUpdateSucceeded, this.onUpdateFailed);

Thanks in Advance

New Update code :-

 var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml("<View><Query></Query><RowLimit>900</RowLimit><ViewFields><FieldRef Name='LookUpColumn' LookupId='TRUE' /></ViewFields></View>");
    items = oList.getItems(camlQuery);
    clientContext.executeQueryAsync(onUpdateSucceeded, onUpdateFailed);

1 Answer 1


You have to request the Property of the item with something like clientContext.load(yourItemCollection , 'Include(LookUpColumn)') or for a single item clientContext.load(yourItem, 'LookUpColumn')

Take a look at Complete basic operations using JavaScript library code in SharePoint and How to include custom fields in clientContext.load

  • Thanks for that but i'm still getting the error after adding "clientContext.load(items,'Include(LookUpColumn)');" and changed the query to :- camlQuery.set_viewXml("<View><Query></Query><RowLimit>900</RowLimit><ViewFields><FieldRef Name='LookUpColumn' LookupId='TRUE' /></ViewFields></View>");
    – naijacoder
    Mar 25, 2019 at 3:09
  • At which line do you get the error? Try to run the following line after loading the Column.... <code>var lookupValue = oListItem.get_item('LookUpColumn'); What's the result?
    – mitti
    Mar 25, 2019 at 15:44
  • Thanks.On this line :- var LookUpColumnId = oListItem.get_item('LookUpColumn')
    – naijacoder
    Mar 26, 2019 at 19:36
  • Please accept the answer if it solved your problem. Thank you.
    – mitti
    Mar 27, 2019 at 9:19
  • mitti that didn't work. The issue i have is this line var oListItem = oList.getItemById(IDs[i]); How can i get the lookup field using the below when using the oListItem from the above //var lookupFieldValue = oListItem.get_item('LookUpColumn'); //var lookupId = lookupFieldValue.get_lookupId(); Thanks
    – naijacoder
    Apr 4, 2019 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.