1

I want to access my property bag using Javascript from a

 <CommandUIHandler
          Command="FCS.Intake.Tab.Reports.TL"
          CommandAction="javascript:
          function getWebProperty() {

        var ctx = new SP.ClientContext.get_current();
        var web = ctx.get_site().get_rootweb();
        this.props =  web.get_allProperties();
        this.props.set_item('aProperty', 'it worked!');
        ctx.load(web);

        ctx.executeQueryAsync(Function.createDelegate(this, gotProperty), Function.createDelegate(this, failedGettingProperty));
    }

    function gotProperty() {
        alert(this.props.get_item('aProperty'));
    }

    function failedGettingProperty() {
        alert('failed');
    }
  getWebProperty();"
        />

But I am getting an error saying " Object has no method 'get_rootweb'. I imagine this is because I haven't registered the sp.js library. If thats the problem, how would I register the sp.js library inside my elements.xml file? (Its all contained inside a element. If thats not the problem, is there a better way to access the property bag using javascript inside a element?

  • what is ctx.get_site() returning? – Abe Miessler May 25 '12 at 23:44
5

I agree with Derek's answer that you have a casing issue. Your issue should be solved by that. Regarding your second question: if you want to make sure that the sp.js is loaded on the page before your code executes, you can do that the following way through elements.xml:

<CommandUIHandler
   Command="FCS.Intake.Tab.Reports.TL"
   CommandAction="javascript:EnsureOrDelayUntilScriptLoaded(function(){
   //Your JavaScript Code here.
   },'sp.js');"
/>
  • Is there a way to access a specific propertybag as opposed to allproperties? – Meyer Denney May 29 '12 at 18:31
  • Sorry for the late reply but I am not really sure what you mean. Do you want to access the property bag of a specific web? – Vardhaman Deshpande Jun 17 '12 at 19:31
  • You can create your own custom property bag for your site collection. I am trying to access that property bag. I got it figured out, see the question sharepoint.stackexchange.com/questions/37198/… for more details – Meyer Denney Jun 17 '12 at 20:13
3

You have a casing issue. The correct format is

ctx.get_site().get_rootWeb()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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