|
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script> |
|
<script type="text/javascript" src="/_layouts/15/sp.js"></script> |
|
<script type="text/javascript" src="/_layouts/15/sp.Taxonomy.js"></script> |
|
<script type="text/javascript"> |
|
//declare namespace |
|
var ConfigureSiteSettings = ConfigureSiteSettings || {}; |
|
|
|
ConfigureSiteSettings.CreateTerm = (function(clientTerm) |
|
{ |
|
var newGuid = new SP.Guid.newGuid(); |
|
var term = document.getElementById("ClientName").value; |
|
|
|
if(!!term ) |
|
{ |
|
//Current Context |
|
var context = SP.ClientContext.get_current(); |
|
|
|
//Current Taxonomy Session |
|
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context); |
|
//termstores |
|
var termStores = taxSession.get_termStores(); |
|
//Term Store under which to create the term. |
|
var termStore = termStores.getByName("Taxonomy_3wUnpxYHSE6OFk/vN07VBQ=="); |
|
//get the parent term ID for "Clients" |
|
var parentTerm = termStore.getTermSet('c2e65e7b-1fdb-4966-8340-0bec832bb02d'); |
|
|
|
var terms = parentTerm.getAllTerms(); |
|
context.load(terms); |
|
context.executeQueryAsync(function(){ |
|
var termEnumerator = terms.getEnumerator(); |
|
var termList = "Terms: \n"; |
|
var termExists; |
|
while(termEnumerator.moveNext()){ |
|
var currentTerm = termEnumerator.get_current(); |
|
termList += currentTerm.get_name() + "\n"; |
|
if(currentTerm.get_name() ==term) { |
|
termExists = true; |
|
break; |
|
} |
|
} |
|
if(!termExists) { |
|
// Create 1st term |
|
var newTerm = parentTerm.createTerm(term, 1033, newGuid); |
|
newTerm.setCustomProperty("Clientid", 4567); |
|
newTerm.setLocalCustomProperty("ClientURL", 7894); |
|
context.load(newTerm); |
|
context.executeQueryAsync(function() {alert(term + " created with shared property Clientid and local property ClientRef")},function(sender,args){ |
|
console.log(args.get_message());}); |
|
} |
|
// alert(termList); |
|
|
|
},function(sender,args){ |
|
console.log(args.get_message()); |
|
}); |
|
} |
|
else |
|
{ |
|
alert("ClientName Empty ! "); |
|
} |
|
}); |
|
</script> |
|
<div> |
|
<p> |
|
<br /> |
|
<b>Configure Term Store Settings</b> |
|
<br /> |
|
<label>Client Name</label><input type="text" value="" id="ClientName" /> |
|
<br /> |
|
<button type="button" id="CreateTerm" onclick="ConfigureSiteSettings.CreateTerm()">Create Term </button> |
|
</p> |
|
</div> |