-1

Setting lookup field & managed meta data field value using jsom. Through jsom I will need to set the value into the list .

Setting the lookup and managed metadata columns through code

mouni
  • 3
  • 2
  • Which version of SharePoint are you working with? The JavaScript for working with lookup columns is the same in 2010, '13, and '16, but taxonomy/managed metadata fields changed between '10 and '13. – Thriggle Sep 12 '17 at 12:18
  • iam looking for 2013 – mouni Sep 12 '17 at 13:20

1 Answers1

0

Try and modify the below sample code:

var clientContext = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);  
var list = clientContext.get_web().get_lists().getByTitle('TestList');  
var itemCreateInfo = new SP.ListItemCreationInformation();  
var listItem = list.addItem(itemCreateInfo);

var singleLookupColumn = new SP.FieldLookupValue();  
singleLookupColumn.set_lookupId(2);  
listItem.set_item('CustomLookup', singleLookupColumn); 

var field = list.get_fields().getByInternalNameOrTitle("TestTaxonomy");  
var taxField = clientContext.castTo(field, SP.Taxonomy.TaxonomyField);  
var taxonomyCol = new SP.Taxonomy.TaxonomyFieldValue();  
taxonomyCol.set_label("Test");  
taxonomyCol.set_termGuid("23d03b66-5be6-512b-9fe3-ff13b9b4757c");  
taxonomyCol.set_wssId(-1);  
taxField.setFieldValueByValue(listItem, taxonomyCol);


listItem.update();  
clientContext.load(listItem);  
clientContext.executeQueryAsync(function(){
    console.log("success");
},function(){
    console.log("error");
});  
Gautam Sheth
  • 2,442
  • 1
  • 17
  • 16