How to programmatically create a TermGroup which is accessible and usable through all SiteCollection
-
05-10-2020 - |
Question
I want to know how to programmatically create a TermGroup which is accessible and usable through all SiteCollection.
Solution
As state here. I used it and it worked for me!
$(document).ready(function(){
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js", function(){
$.getScript(scriptbase + "SP.Taxonomy.js", execOperation);
});
}
);
});
function execOperation(){
//Current Context
var context = SP.ClientContext.get_current();
//Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStores = taxSession.get_termStores();
//Term Store under which to create the group.
var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
//New Group with name and new GUID
var newGroup = termStore.createGroup("New Group Name","b300304a-1693-4629-a1c0-dff7bda644ff");
context.load(newGroup);
context.executeQueryAsync(function(){
console.log(newGroup.get_name());
},function(sender,args){
console.log(args.get_message());
});
}
For c# see here. I did not test it!
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange