Search code examples
javascriptjquerysharepointspservices

How to read a property from the FARM property bag using jquery or SPServices


The question its very clear, I lknow how to read a property from the property bag in c#

But now I need to know how to do it in jquery or with SPServices. Any idea?

Thanks


Solution

  • 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.getPropertyBagSuccess), function.createDelegate(this, this.getPropertyBagFail));
    }
    
    function getPropertyBagSuccess() {
        var propertyBag = webProperties.get_fieldValues();
        if(propertyBag.YourProperty != undefined)
        {
            alert(propertyBag.YourProperty);
        }
        else
        {
            alert("property not found!");
        }
    }
    
    function getPropertyBagFail(args, sender)
    {
        alert("error trying to read propertybag");
    }