Wednesday, September 30, 2015

CSOM code to fetch the property bag value

You can add the property to web property bag from designer.


Below is the code that you can use to get the added property

ExecuteOrDelayUntilScriptLoaded(getWebProperties, "sp.js");

var webProperties;

function getWebProperties() {
    var clientContext = new SP.ClientContext.get_current();
    webProperties = clientContext.get_web().get_allProperties();
    clientContext.load(webProperties);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.getWebPropertiesSucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function getWebPropertiesSucceeded() {

          //debugger; //use this to force a break here
    //returns an object with all properties.  
          //Use the quick watch to expand this out to see all of them.
    var allProps = webProperties.get_fieldValues();

    var customProp = "";

         //make sure the property is there before using it.
    if(webProperties.get_fieldValues().YammerAccessToken != undefined)
    {
        var customProp = webProperties.get_fieldValues().YammerAccessToken;
    }
    alert(customProp);
}

function onQueryFailed(args, sender)
{

     //handle errors here
 alert("Error : " + args.get_message());
}
getWebProperties();

No comments:

Post a Comment