I am creating a hosted app in SharePoint. I want to retreive all the custom list from SharePoint and then from the custom lists I want to fetch column values. I got 2 columns with the names title and link. Link is a hyperlink column containing urls. My question is some of my custom lists doesnt have the column name "link" and some has. But I want to retreive those list that has that column. And title column is in every custom list. Some of the list has the column name "link" but with no values.
Error message: 0x800a138f - Runtime errors in JavaScript: Unable to retrieve the property get_url for a reference that is undefined or null
function onSuccessItemFetch() {
// Now you can access the array of SP.ListItemCollection
for (var i = 0, length = listItemsCollection.length; i < length; i++) {
var items = listItemsCollection[i];
var enumerator = items.getEnumerator();
while (enumerator.moveNext()) {
var listItem = enumerator.get_current();
if (typeof listItem.get_item('Link') != "undefined" && typeof listItem.get_item('Link') != null) {
itemString += listItem.get_item('Title') + " " + " " + " " + " " + " " + " " + "<a href='" + listItem.get_item('Link').get_url() + "'>" + "öppna formulär" + "</a>" + "</br>"; //oListItem.get_item('Datum')
$('#divAllaListItems').html(itemString);
}
}
}
}
It works fine when I want to retrieve all the custom list titles and the title column values.
listItem.get_item('Link')
is defined before you try to setitemString
?.get_url()
method on an object that doesn't exist, so yes that should stop execution. So you should check whether the object exists before using it. So something likeif(listItem.get_item('Link')) var linkURL = listItem.get_item('Link').get_url();