0

I'm pretty new in SP and I'm stuck with this! i created a list "cities" with 2 columns "Namn" and "lalala" with my code only works to show the first column but not the second. this is my working code, i've tried both from Visual Studio and NAPA

'use strict';
var clientContext = new SP.ClientContext.get_current();
var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var parentContext = new SP.AppContextSite(clientContext, hostweburl);
var parentWeb = parentContext.get_web();
var list = parentWeb.get_lists().getByTitle("cities").getItems("");

$(document).ready(function () {

clientContext.load(list);
clientContext.executeQueryAsync(onSuccess, onFail);
});
function onSuccess() {
var listColumnTitle = "";
var listEnumerator = list.getEnumerator();
while (listEnumerator.moveNext()) {
    var currentItem = listEnumerator.get_current();
listColumnTitle += "<li>"+ currentItem.get_item("Title"); //This works like this. but the column name is "Namn" if i write "Namn" it'll not work. if i add + currentItem.get_item("lalala") it doesn't work either.
}
$("#minDiv").html(listColumnTitle);
}
function onFail() {
alert("ERROR");
}

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];
}
}

Thanks in advance!! Michel

MicMor
  • 1
  • 1

1 Answers1

1

get_item() wants the internal name of the column. "Title" is the internal name while "Namn" is the Display Name.

Find more about Internal Names and Display Names in this excellent answer: https://sharepoint.stackexchange.com/a/792/3221

Vardhaman Deshpande
  • 10,462
  • 1
  • 26
  • 52