Question

I cant run my code. I get this error message:

0x800a139e - Runtime Errors in JavaScript : The property or field has not been initialized . There has been no request or has not been performed. It might need to be requested specifically.

I created an app (custom list) on developer site. In that list I created 3 columns (Title, Status and Responsible). And I also added some items to fetch them with my code. It displays column titles but when I want to fetch Resposible column it give me the error. In appManifest I added Web to Full Control.

'use strict';

var context = new SP.ClientContext.get_current();
var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var parentContext = new SP.AppContextSite(context, hostweburl);
var parentWeb = parentContext.get_web();
var listitemCollection = parentWeb.get_lists().getByTitle("CaseList").getItems("");


$(document).ready(function () {

    context.load(listitemCollection);
    context.executeQueryAsync(onSuccess, onFail);
});

function onSuccess() {

    var itemString1 = "";
    var itemString2 = "";
    var itemString3 = "";

    var listEnumerator = listitemCollection.getEnumerator();
    var currentItem;

    while (listEnumerator.moveNext()) {
        currentItem = listEnumerator.get_current();
        if (currentItem.get_item('Status') == "New") {
            itemString1 += "<br/>" + currentItem.get_item('Title') + " " + currentItem.get_item('Responsible');
        }
        else if (currentItem.get_item('Status') == "Started") {
            currentItem = listEnumerator.get_current();
            itemString2 += "<br/>" + currentItem.get_item('Title') + " " + currentItem.get_item('Responsible');
        }
        else if (currentItem.get_item('Status') == "Finished") {
            currentItem = listEnumerator.get_current();
            itemString3 += "<br/>" + currentItem.get_item('Title') + " " + currentItem.get_item('Responsible');
        }
    }

    $("#Show1").html(itemString1);
    $("#Show2").html(itemString2);
    $("#Show3").html(itemString3);
}

function onFail(sender, args) {
    alert("Error:" + args.get_message());
}

function getQueryStringParameter(paramToRetrieve) {
    var params = document.URL.split("?")[1].split("&");
    var strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
        var singleParam = params[i].split("=");
        if (singleParam[0] == paramToRetrieve)
            return singleParam[1];
    }
}
Was it helpful?

Solution

You can request for additional fields using

 context.load(listitemCollection, 'Include(Responsible,Status)');

OTHER TIPS

Maybe for some items that column value is null or empty.

Check this condition each time you are retrieving some column values:

item.get_item('internalColumnName')!= null
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top