3

I am trying to run the following code in a simple sharepoint app, but I got this error:

Uncaught Error: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. 

Code is this one:

var collListItems;
$(document).ready(function () {
    getConfigValues();
});
function getConfigValues() {
    var context = SP.ClientContext.get_current();
    var configList = context.get_web().get_lists().getByTitle('Configuration Values');
    var camlQuery = new SP.CamlQuery();
    collListItems = configList.getItems(camlQuery);
    context.load(collListItems);
    context.executeQueryAsync(onGetConfigValuesSuccess, onGetConfigValuesFail);
}
function onGetConfigValuesSuccess() {
    var OrgLogoUrl;
    var OrgName;
    var listItemEnumerator = collListItems.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        var current = oListItem.get_item('Title');
        switch (current) {
            case 'OrganizationName':
                OrgName = oListItem.get_item('Value');
                break;
            case 'OrganizationLogoUrl':
                OrgLogoUrl = oListItem.get_item('Value');
                break;
        };
    }
    if (OrgName && OrgName.length > 0) {
        $('#DeltaPlaceHolderPageTitleInTitleArea').html(OrgName);
        $('.ms-siteicon-img').attr('title', OrgName);
    }
    if (OrgLogoUrl && OrgLogoUrl.length > 0)
        $('.ms-siteicon-img').attr('src', OrgLogoUrl);
    else
        $('.ms-siteicon-img').attr('src', '../Images/AppLogo.png');
}
function onGetConfigValuesFail(sender, args) {
    alert('Failed to get the Configuration Values. Error:' + args.get_message());
}

The code is from a book, without any modifications:

OrgName = oListItem.get_item('Value');
1

Instead of Value use some other column name in the list. I have used Test in my case.

then do the following code changes in onGetConfigValuesSuccess function

function onGetConfigValuesSuccess() {
    var OrgLogoUrl;
    var OrgName;
    var listItemEnumerator = collListItems.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        var current = oListItem.get_item('Title');
        switch (current) {
            case 'OrganizationName':
                OrgName = oListItem.get_item('Test');
                break;
            case 'OrganizationLogoUrl':
                OrgLogoUrl = oListItem.get_item('Test');
                break;
        };
    }
}
4

The specified error could occur due to one of the following reasons:

  1. Column with Internal Name Value does not exist in the List Configuration Values

    Since SP.ListItem.item property expects field Internal Name, please make sure the field with such a name exists in List.

  2. List Item value for a field Value could not be loaded implicitly.

    Try explicitly specify what List Item properties to load using SP.ClientContext.load method. The solution, to replace the line:

    context.load(collListItems);
    

    with

    context.load(collListItems,'Include(Title,Value)');
    
  • In my case, I had to open the Schema.xml file for the ConfigurationValues list. I noticed that the Internal Name given was "Value1", not "Value". Changing either the script to use Value1 or the list internal name to be Value fixed. – danludwig Nov 24 '14 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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