1

I am attempting to update a list outside of my app web. When I find the list, I am finding my column, then casting that into a TaxonomyField. The purpose of casting is to be able to play with get_termGuid() which would then let me get to set_termGuid.

The following works just fine, but I'm not getting the results that I am expecting. myField.get_typeDisplayName() gives me 'Managed Metadata'

but using taxFieldValue.get_termGuid() gives me "". So when I attempt to load taxFieldValue, I get

'Object doesn't support property or method 'get_$19_0''

Something seems off, what am I missing here? Most of the samples that I have seen out there are for getting the value of a specific list item. What I am trying to do is alter the Term Store Settings for a specific list column. Not seeing too much out there on that.

edit also, I was then looking at what the process is for creating a new list column using JavaScript and noticed that the only option for this type of column is addFieldAsXml. So that did not help out my situation any.

var appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));    
var clientContext = new SP.ClientContext.get_current();
var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
siteUrl = hostweburl + '/' + url;
var hostcontext = new SP.AppContextSite(clientContext, siteUrl);    
oWeb = hostcontext.get_web();    
oList = oWeb.get_lists().getByTitle(title);

listFields = oList.get_fields();  

myField = listFields.getByInternalNameOrTitle("ACKeyWord");    
taxField = clientContext.castTo(myField, SP.Taxonomy.TaxonomyField);     
taxFieldValue = taxField.getFieldValueAsTaxonomyFieldValue();    

clientContext.load(oList);    
clientContext.load(myField);
clientContext.load(taxField);

clientContext.executeQueryAsync(Function.createDelegate(this, onListFieldsSucceeded), Function.createDelegate(this, onListFieldsFailed));
1

In order to manage TaxonomyField properties there is no need to utilize SP.Taxonomy.TaxonomyField.getFieldValueAsTaxonomyFieldValue Method

The following example demonstrates how to print TaxonomyField specific properties

var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();    
var list = web.get_lists().getByTitle(listTitle);

var field = list.get_fields().getByInternalNameOrTitle(fieldName);    

ctx.load(field);
ctx.executeQueryAsync(
    function(){
        var taxField = ctx.castTo(field, SP.Taxonomy.TaxonomyField);

        //print Taxonomy Field specific properties
        console.log(taxField.get_sspId().toString().toString());
        console.log(taxField.get_anchorId().toString());
        console.log(taxField.get_termSetId().toString());
    },  
    function (sender, args) {
       console.log(args.get_message());
    }
);

Your Answer

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

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