0

I can successfully create a sub-site from a custom template using the REST api and jQuery from MSDN example. But is there a way to set custom propertybag key values in the process?

For example, the site template has the custom propertybag keys of myRegion, myGroup, myType, myDate that I would like to be dynamic based on entries in form fields. Can I set these values when the ajax call is made? If I try to set them as parameters I get the error...

"The property 'myRegion' does not exist on type 'SP.WebInfoCreationInformation'. Make sure to only use property names that are defined by the type."

That tells me that SP.WebInfoCreationInformation is looking for specific key/value pairs but I can't find a listing anywhere.

CGann
  • 3
  • 1

1 Answers1

0

You can try using CSOM. Something like this -

function setWebProperties() {

var execOperation = function () {
    var ctx = new SP.ClientContext.get_current();
    var web = ctx.get_web();
    this.properties = web.get_allProperties();

    this.properties.set_item("<propKey>", "<propValue>");
    ctx.load(web);
    web.update();

    ctx.executeQueryAsync(function fSuccess(data) {
        alert(this.properties.get_item("<propKey>"));
    }, function fError(sender, args) {
        alert("Error - " + args.get_message());
    });
}
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', execOperation);
}
JJJ
  • 32
  • 2
  • Thank you for your response. I will try this approach but modify SP.ClientContext.get_current() to get the sub-site by using its url. – CGann Aug 27 '15 at 13:10
  • I tried this approach, modifying SP.ClientContext.get_current() to get the sub-site by using its url. [i.e. ctx = new SP.ClientContext(webUrl)] and it worked perfectly!!! – CGann Aug 27 '15 at 13:37
  • Now here's an interesting dilemma- It doesn't work all the time. Not quite sure what's going on. I'm setting the values, updating the target web, then even re-loading that web's properties and checking that the values have been updated and outputting to the console. In the code, it works. but when I check the site manually via '/_api/web/allProperties', roughly 1 our of 6 times it fails. – CGann Sep 13 '15 at 19:26