使用CSOM和javascript创建Taxonomy子术语

时间:2013-06-09 16:37:23

标签: javascript taxonomy sharepoint-2013 csom

在sharepoint托管元数据中我发现很少有关于使用javascript CSOM管理术语的文档。我可以直接在术语集下创建一个分类术语,但我想在另一个术语下创建一个术语作为子项,就像在术语库窗口中一样。

function createTerm(){
//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 term.
var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
//Term Set under which to create the term.
var termSet = termStore.getTermSet("b49f64b3-4722-4336-9a5c-56c326b344d4");
//Name of the term, LCID and a new GUID for the term.
var newTerm = termSet.createTerm("India", 1033, "b49f64b3-4722-4336-9a5c-56c326b344a9");
//newTerm.set_isAvailableForTagging(true);
context.load(newTerm);
context.executeQueryAsync(function(){
alert("Term Created: " + newTerm.get_name());
 },function(sender,args){
console.log(args.get_message());
});
}

1 个答案:

答案 0 :(得分:5)

要在父条款下添加字词,您需要:

  • 术语商店ID和相关术语集
  • 父条款ID(将添加新子条款)

代码:

 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 term.
    var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");

    //Term Set under which to create the term.
    var termSet = termStore.getTermSet("b49f64b3-4722-4336-9a5c-56c326b344d4");


    //get the parent term ID, say it's "cf46hujkl-3344-4336-9a5c-56c326b344d4"
    var parentTerm = termSet.getTerm("cf46hujkl-3344-4336-9a5c-56c326b344d4");

    //create new child term under the parent term
    var newTerm = parentTerm.createTerm("SharePoint Rocks", 1033, newGuid.toString());

    context.load(newTerm);
    context.executeQueryAsync(function(){
    alert("Term Created: " + newTerm.get_name());
     },function(sender,args){
    console.log(args.get_message());
    });}