0

I am creating an SharePoint hosted app. In that I have to use Managed MataData from my list. In this I am getting the Metadata from my list column to my Taxonomy control.

I have find some post but I am not able to get the all the meta data. Code I am using is as below.

function execOperation() {
    try {
        context = new SP.ClientContext(hostweburl);
        var factory =
            new SP.ProxyWebRequestExecutorFactory(
                appweburl
            );
        context.set_webRequestExecutorFactory(factory);
        appContextSite = new SP.AppContextSite(context, hostweburl);
        web = appContextSite.get_web();
        context.load(web);
        //My List with Taxonomy column
        taxonomyList = web.get_lists().getByTitle("Test");

        context.executeQueryAsync(onSuccess, onFail);
    }
    catch (err) {
        alert(err.message);
    }
}

function onSuccess() {
    try {
        debugger;
        //Getting the taxonomy filed from the list
        taxonomyControl = taxonomyList.get_fields().getByInternalNameOrTitle("Name");
        context.load(taxonomyControl);
        taxField = context.castTo(taxonomyControl, SP.Taxonomy.TaxonomyField);
        context.load(taxField);
        context.executeQueryAsync(onSuccessTaxonomyValues, onFail);

    }
    catch (err) {
        alert(err.message);
    }
}

//This code is suppose to fill the taxonomy filed. But it is not working.
function onSuccessTaxonomyValues() {
    debugger;
    var webTaggingCtl = $get("ctl00_PlaceHolderMain_ctl01editableRegion");//On page taxonomy control.
    var taxCtlObj = new SP.Taxonomy.ControlObject(webTaggingCtl);
    taxCtlObj.enableControl(true);
    taxCtlObj.setRawText(taxField);
    taxCtlObj.retrieveTerms();
}

My actual question is How can I fill TaxonomyWebTaggingControl control, which I placed on my page, with the above code? Can any one help me to solve this? Thank you in advance...!

1 Answer 1

0

Looks like you are calling your callback functions, rather than passing a reference to them into executeQueryAsync. Your callbacks are probably executing before the data has been retrieved.

Have you tried this

context.executeQueryAsync(onSuccessTaxonomyValues, onFail) 

instead of this

context.executeQueryAsync(onSuccessTaxonomyValues(), onFail());

and this

context.executeQueryAsync(onSuccessTaxonomyValues, onFail);

instead of this

context.executeQueryAsync(onSuccessTaxonomyValues(), onFail());
4
  • The success methods here are getting executed. Nothing it take if I pass braces there. My Actual question is how can I fill TaxonomyWebTaggingControl with this code. Commented Jan 24, 2014 at 5:15
  • And if I remove braces from the method It gives me error. I have asked Question please check If you can solve. sharepoint.stackexchange.com/questions/88653/… Commented Jan 24, 2014 at 6:18
  • What is the error when you remove the parentheses?
    – Paul Lucas
    Commented Jan 28, 2014 at 22:50
  • The Error has been solved. But this is still remains that how to use Taxonomy control. Commented Jan 29, 2014 at 4:24

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.