2

在 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());
});
}
4

1 回答 1

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());
    });}
于 2013-06-10T07:59:53.963 回答