Question regarding the client object model. I wrote some client script for a procedure, but i don't know, how can I determine if the list or item has the field available or not? For example:
this.listItem.get_item("_dlc_DocId");
This code will execute very wel if the field "_dlc_DocID" is available in the list, but it is also possible that this field will not be available because of the feature that is deactivated, then it will throw an error. And nothing will execute further, so i need some kind of a check to see if this field is available or not. Anyone has any idea? I tried:
list.get_fields().GetByInternalNameOrTitle("_cld_DocID")
But no success ... do i miss something?
Here is the whole code:
function CreateLink() {
var ctx = SP.ClientContext.get_current();
this.web = ctx.get_web();
this.site = ctx.get_site();
var listId = SP.ListOperation.Selection.getSelectedList();
this.list = this.web.get_lists().getById(listId);
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var mijnid = items[0];
this.listItem = list.getItemById(mijnid.id);
ctx.load(this.list);
ctx.load(this.listItem);
ctx.load(this.web, 'ServerRelativeUrl');
ctx.load(this.site, 'ServerRelativeUrl', 'Url');
ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
var title = this.listItem.get_item('FileLeafRef');
var webRelativeUrl = this.web.get_serverRelativeUrl();
var siteUrl = this.site.get_url();
var webAppUrl = siteUrl.replace(webRelativeUrl, "");
var url;
var dlcdocid=this.list.get_fields().getByInternalNameOrTitle("_dlc_DocIdSome");
.... todo
}