3

I am trying to add a label to a term using the following code:

    var taxonomyContext = SP.ClientContext.get_current();
    var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(taxonomyContext);
    var termStores = taxonomySession.get_termStores();
    var termStore = termStores.getByName("TaxonomyName");
    var projectNumberTermSet = termStore.getTermSet("termsetid");

    var term = projectNumberTermSet.getTerm("theguid");

    taxonomyContext.load(term);

    var newLabel = term.createLabel("new label name", 1033, false);

    taxonomyContext.load(newLabel);

    taxonomyContext.executeQueryAsync(successHandler, errorHandler);

The following error is returned:

Could not complete cross-domain call: Access denied. You do not have permission to perform this action or access this resource.

I am able to successfully add terms to the same termstore via javascript, so not sure how it can actually be a permissions problem.

The platform is Office 365.

The code is running in a sharepoint-hosted app.

Anyone come across this issue before?

1 Answer 1

2

On SP On-premises, your code doesn't work anymore. So I guess, that's really not a permission problem. Please find below the code which is working on my machine :

function addNewLabel(){
        var context = SP.ClientContext.get_current();
        var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
        var termStore = taxonomySession.getDefaultSiteCollectionTermStore();
        var termSets = termStore.getTermSetsByName("Language", 1033);
        var termSet = termSets.getByName("Language");
        var terms = termSet.getAllTerms();
        context.load(terms);
        context.executeQueryAsync(function onSuccess() {
            var term = terms.get_data()[0];
            var newLabel = term.createLabel("new label name", 1033, false);
            context.load(newLabel);
            context.executeQueryAsync(function onSuccess(){
            }, function onFailure(args) {
                alert('Error: '+args);
            });
        }, function onFailure(args) {
            alert('Error: '+args);
        });
    }

I'm loading all terms for a specific termset and taking the first one to pass a new label. There are two different async calls, that's maybe your error.

Regards,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.