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?

Meyer Denney
  • 2,864
  • 8
  • 37
  • 64

2 Answers2

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');"
/>
Vardhaman Deshpande
  • 10,462
  • 1
  • 26
  • 52
  • 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 http://sharepoint.stackexchange.com/questions/37198/grab-a-specific-property-bag-using-ecma-script 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()
Derek Gusoff
  • 8,011
  • 1
  • 17
  • 15