none
How do you assign SPWeb property bag values in JSOM? RRS feed

  • Question

  • Basically I'm trying to assign SPWeb property bag value using JavaScript OM or API call ... here is the equivalent in c# but since it's a SharePoint app I can only use JS

    SPWeb web = SPContext.Current.Web;

    web.AllProperties["MyProperty"]="Value";
    web.Update();

    Thursday, April 11, 2013 6:16 PM

Answers

  • Hi,

    Using JavaScript you do a similar thing but with the get/set methods:

    function setWebProperty() {

        var ctx = new SP.ClientContext.get_current();

        var web = ctx.get_web();

        this.properties = web.get_allProperties();

        this.properties.set_item("myCustomProperty", "myCustomValue");

        ctx.load(web);

        web.update();

        ctx.executeQueryAsync(Function.createDelegate(this, getWebProperty), Function.createDelegate(this, failedGettingProperty));

    }

    function getWebProperty() {

        alert(this.properties.get_item("myCustomProperty"));

    }

    function failedGettingProperty() {

        alert("failed");

           }

    Cheers,

    Yina

    Friday, April 12, 2013 6:54 AM