SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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:


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(); = 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(;

    ctx.load(this.web, 'ServerRelativeUrl');
    ctx.load(, '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 =;
    var webAppUrl = siteUrl.replace(webRelativeUrl, "");
    var url;    
    var dlcdocid=this.list.get_fields().getByInternalNameOrTitle("_dlc_DocIdSome");

   .... todo
share|improve this question
up vote 3 down vote accepted

Found a proper javascript client object model solution for my problem: Here is the solution:

this.listFields = list.get_fields();

And then in the function: onQuerySucceeded

var fieldEnumerator = this.listFields.getEnumerator();
    while (fieldEnumerator.moveNext()) {
        var field = fieldEnumerator.get_current();
        var name = field.get_staticName();
        if (name == "_dlc_DocId") {
            docFeatureEnabled = true;

I hope this helps and can spare some time for people.

share|improve this answer
string siteUrl = "http://MyServer/sites/MySiteCollection"; 
        ClientContext clientContext = new ClientContext(siteUrl); 
        SP.List List = clientContext.Web.Lists.GetByTitle("my forum"); 
        for (int i = 0; i < list.Fields.Count; i++) 
           if (list.Fields[i].Title == "xyz") 

I have stolen this from

share|improve this answer
i know i tried this, but it doesn't work :( – Shkipper Sep 10 '12 at 9:47
on this line: for (int i = 0; i < list.Fields.Count; i++) i get error missing ";" :( – Shkipper Sep 10 '12 at 9:47
and even if im in debug mode and i try to add list.Fields it says no such property is defined :( – Shkipper Sep 10 '12 at 9:49
does list.get_fields() get you anything? you mentioned in your post you had tried this? If it does then you can count the fields that this returns and replace the list.Fields.Count with an interger variable. – Truezplaya Sep 10 '12 at 10:11
yeah it returns an object, but i dont know ... if i enumarte with it like for(var f in list.get_fiels()) then it returns like all methods and properties etc :/ – Shkipper Sep 10 '12 at 10:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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