Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
what is ctx.get_site() returning? –  Abe Miessler May 25 '12 at 23:44
add comment

2 Answers

up vote 5 down vote accepted

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');"
/>
share|improve this answer
    
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
add comment

You have a casing issue. The correct format is

ctx.get_site().get_rootWeb()
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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