онлайн JS в TypeScript Converter
static async EnsureTaxKeyword(taxValue){
return new Promise(function (resolve, reject) {
window.ExecuteOrDelayUntilScriptLoaded(function () {
window.ExecuteOrDelayUntilScriptLoaded(function () {
var locale = 1033;
var listContext = window.SP.ClientContext.get_current();
var taxSession = window.SP.Taxonomy.TaxonomySession.getTaxonomySession(listContext);
var termStore = taxSession.getDefaultKeywordsTermStore();
var termSets = termStore.getTermSetsByName("Keywords", locale);
var termSet = termSets.getByName("Keywords");
listContext.executeQueryAsync(() => {
var terms = termSet.getAllTerms();
var term = terms.getByName(taxValue);
listContext.load(term);
listContext.executeQueryAsync(() => {
console.log(term);
const termid = term.get_id().toString();
console.log(termid);
resolve(termid);
}, (sender1, args1) => {
console.log("Term not found. Create new Term");
console.log(args1);
const newGuid = new window.SP.Guid.newGuid();
let newTerm = termSet.createTerm(taxValue, 1033, newGuid.toString());
listContext.load(newTerm);
listContext.executeQueryAsync(() => {
const newTermId = newTerm.get_id().toString();
console.log("created new term:" + newTermId);
resolve(newTermId);
}, (sender1, args2) => {
console.log("Error while creating term");
console.log(args2);
reject("Error:" + args2.get_message());
});
});
}, (sender1, args3) => {
console.log("Error while retrieving term set");
console.log(args3);
reject("Error:" + args3.get_message());
});
}
, "SP.Taxonomy.js");
}
, "SP.js");
});
}
Scary Skipper