I have a list called Employees , i created a custom form for saving the data. The custom form holds five fields. Which are created using normal html input tags

  1. Name: (input type = text)
  2. ID: (input type= number)
  3. Country:(input type = select which consist of options they are dynamically added from metadata)
  4. State: (input type = select which consist of options they are dynamically added based on the selection of Country field)
  5. ContactNo: (input type = number)
  6. Submit: (input type = button)

Columns in Employee Details

  1. Name (type = string)
  2. Id (type = number)
  3. Country (type = managed metadata having Country Metdata)
  4. State (type = managed metadata having State Metadata)
  5. ContactNo (type = number)

Meta Data Management Structure

EmployeesDetails(Term Set)
             New Delhi(Term)

So when we are saving the record it should save to the corresponding columns. I am able to list state based on the selection of country from managed meta data. How can i save the record to the corresponding columns of state and country which are managed meta data columns using javascript?

Many regards

1 Answer 1


you may try the below function to update the metadata fields

 function ExecUpdate(endpointUrl, itemTerm) {
        var headers = {};
        headers["X-HTTP-Method"] = "MERGE";
        headers["If-Match"] = "*";

        headers["Accept"] = "application/json;odata=verbose";
        headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val();
        var method = 'POST';
        var ajaxOptions =
            url: url,
            type: method,
            contentType: "application/json;odata=verbose",
            headers: headers
        if (typeof itemterm != 'undefined') {
            ajaxOptions.data = JSON.stringify(itemTerm);
        return $.ajax(ajaxOptions);

and you can set the variables as below

    var listName = 'list name';  //set list name
    var itemId = 1; //set item id
    var webUrl = _spPageContextInfo.webAbsoluteUrl;
    var endpointUrl = webUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items(" + itemId + ")";
    var fieldName = 'field name';  // field name
    var itemTerm = {
        '__metadata': { 'type': 'SP.Data.ContactsListItem' },
        fieldName: {
            '__metadata': { 'type': 'SP.Taxonomy.TaxonomyFieldValue' },
            'Label': 'set term label',  //set term label 
            'TermGuid': '73ggdtes-8weg-6dsg-f982-9djksh6dvd34',  //set term guid 
            'WssId': -1
    ExecUpdate(endpointUrl, itemTerm)

you may also check a similar post here

  • I tried the code and the post that you have shared it doesn't seems to work. I have updated my question , i hope it can give you a better understanding Thanks in advance..
    – Learner
    Feb 23, 2018 at 4:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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