0

I can retrieve existing properties using REST (web/AllProperties) from site collections. As the title states, I would like to add custom property bag values to the property bag on a site collection, using REST. Is this possible?

2 Answers 2

1

AllProperties is a SPPropertyValues collection. It has a SetFieldValue method that takes the field name and an object as arguments. This method is not available from REST since the value argument can be anything. REST call arguments can only be primitive types or known EDM types. You can call this method using javascript and JSOM.

1
  • Thanks! I already started using JSOM, and got my app working
    – JazzVH
    Jun 2, 2015 at 14:03
0

The answer NO. You can not update the spweb properties using REST. You can use JSOM as suggested in the first answer and below is the code that I found and tested here: How do you assign SPWeb property bag values in JSOM

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");
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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