I know how to get all the fields in a list using CSOM/JSOM. What I cannot figure out is how to get the source field for computed fields.

For example, the LinkTitle field is a computed field soured from the Title field. So if I have the LinkTitle field, how would I get the name of the source field.

    var listData = {};
    listData.clientContext = SP.ClientContext.get_current();
    listData.list = listData.clientContext.get_web().get_lists().getByTitle("test");
    listData.listFields = listData.list.get_fields();

    listData.clientContext.load(listData.list, "EffectiveBasePermissions");

    listData.clientContext.executeQueryAsync(Function.createDelegate(listData, listDetailsLoaded), Function.createDelegate(listData, function(sender, args){if(this.onError) this.onError(1, args.get_message());}));
}, "sp.js");

function listDetailsLoaded(sender, args)
    var listData = this;
    var fieldEnumerator = listData.listFields.getEnumerator();
        var thisField = fieldEnumerator.get_current();

        if(thisField.get_fieldTypeKind() == 12)
            alert('computed field: ' + thisField.get_internalName());
            // get source field here
  • You could retrieve the SchemaXml and parse the XML to find the FieldRefs – Nsevens Oct 17 '16 at 8:59
  • That is what I am doing right now but I felt as though there HAS to be a less-hacky way... – IMTheNachoMan Oct 17 '16 at 21:11
  • 1
    @IMTheNachoMan FWIW, SP Designer 2013 parses the SchemaXML to find the possible choice values for a site column. Here's the query it generates. So, sometimes, that is the least hacky way. I suppose it's a catch-all for CSOM, in case a given feature isn't available. – jpaugh Sep 18 '17 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.