1

I am struggling getting taxonomy into a metadata column using JSOM. I cannot find any great learning manual for JSOM.

var fieldSchema = `<Field Type="TaxonomyFieldTypeMulti" 
                           Name="SessionTopics" 
                           DisplayName="Session Topics"
                         Required="TRUE" 
                        Group="Limited Document Library" />`;

    fields.addFieldAsXml(fieldSchema, false, SP.AddFieldOptions.AddFieldInternalNameHint);

this creates the site column, pretty easy but now I want to add the taxonomy term into the column using JSOM. I have found plenty of information on how to update a column, but to actually assign a term into the column, I am really struggling. HELP!!!

0

Try using below JSOM code:

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

var taxField =  
        '<Field Type="TaxonomyFieldType" DisplayName="Location"  ShowField="Term1033" Required="FALSE" EnforceUniqueValues="FALSE"  StaticName="Location" Name="Location" > \
             <Default /> \
             <Customization> \
                <ArrayOfProperty> \
                  <Property><Name>SspId</Name><Value xmlns:q1="http://www.w3.org/2001/XMLSchema" p4:type="q1:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">b5b6effd-4925-43e4-ad43-a257213dedec</Value></Property> \
                  <Property><Name>TermSetId</Name><Value xmlns:q2="http://www.w3.org/2001/XMLSchema" p4:type="q2:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">b49f64b3-4722-4336-9a5c-56c326b344d4</Value></Property> \
                  <Property><Name>AnchorId</Name><Value xmlns:q3="http://www.w3.org/2001/XMLSchema" p4:type="q3:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">00000000-0000-0000-0000-000000000000</Value></Property> \
                  <Property><Name>UserCreated</Name><Value xmlns:q4="http://www.w3.org/2001/XMLSchema" p4:type="q4:boolean" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">false</Value></Property> \
                  <Property><Name>Open</Name><Value xmlns:q5="http://www.w3.org/2001/XMLSchema" p4:type="q5:boolean" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">true</Value></Property> \
                  <Property><Name>TextField</Name><Value xmlns:q6="http://www.w3.org/2001/XMLSchema" p4:type="q6:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{155963e0-be13-5b99-bb2b-df69fdcbbeec}</Value></Property> \
                  <Property><Name>IsKeyword</Name><Value xmlns:q8="http://www.w3.org/2001/XMLSchema" p4:type="q8:boolean" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">false</Value></Property> \
                  <Property><Name>CreateValuesInEditForm</Name><Value xmlns:q9="http://www.w3.org/2001/XMLSchema" p4:type="q9:boolean" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">false</Value></Property> \
                </ArrayOfProperty> \
               </Customization> \
          </Field>';


list.get_fields().addFieldAsXml(taxField, true, SP.AddFieldOptions.defaultValue);
context.executeQueryAsync(function() {
       console.log("Managed metadata field provisioned successfully");
    },
    function(sender, args) {
       console.log(args.get_message());
    }
);

Reference: How to create a Document Library with Metadata Column using JSOM

| improve this answer | |
  • Also check the field schema given here if it helps. – Ganesh Sanap Jan 24 at 14:36
  • Hi @Jason, Have you tried this? Is it working for you?/ – Ganesh Sanap Jan 27 at 9:44

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.