PropretyBag with JavaScript in SharePoint 2013




Hello,
as we know, Property bag are very important in SharePoint development, and to get it with JavaScript is very simple :



//wait until client object model dependencies are loaded before executing our code
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().CustomSite_Version != undefined)
    {
        var customProp = webProperties.get_fieldValues().CustomSite_Version;
    }
    alert(customProp);
}
function onQueryFailed(args, sender)
{
     //handle errors here
}



-----------
var customProp = webProperties.get_fieldValues().CustomSite_Version;
Powered by Blogger.