0

how can I add a property let say "StartDate" to the subweb i just created in this code,

var clientContext;
var website;
var subweb;

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

function sharePointReady() {
    clientContext = SP.ClientContext.get_current();
    website = clientContext.get_web();
    clientContext.load(website);
    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
}
function onRequestSucceeded() {
    var WCI = new SP.WebCreationInformation();
    WCI.set_webTemplate('STS#0');
    WCI.set_description('abc6');
    WCI.set_title('abc6');
    WCI.set_url("abc6");
    WCI.set_language(1033);

    subweb = website.get_webs().add(WCI);
    website.update();
    clientContext.executeQueryAsync(onRequestSucceeded2, onRequestFailed);
}
function onRequestSucceeded2() {
    alert("done!");
}
function onRequestFailed() {
    alert("Failed");
}
2

From Making use of the Property Bag in the ECMAScript Client Object Model

function getWebProperty() {
    var ctx = new SP.ClientContext.get_current();
    var web = ctx.get_site().get_rootweb();
    this.props =  web.get_allProperties();
    this.props.set_item("aProperty", "aValue");
    ctx.load(web);

    ctx.executeQueryAsync(Function.createDelegate(this, gotProperty), Function.createDelegate(this, failedGettingProperty));
}

function gotProperty() {
    alert(this.props.get_item("aProperty"));
}

function failedGettingProperty() {
    alert("failed");
}
  • any way to make these values indexable (particularly in SharePoint Online)? – Brent Ellis Apr 3 '14 at 17:42
  • You mean so you can search on them? – Rob Windsor Apr 3 '14 at 18:50
  • Yes, i've used similar code before to inject properties into a web's property bag, but they don't get crawled in SharePoint Online. – Brent Ellis Apr 3 '14 at 19:00
  • The properties are meant to be used for configuration type information and are never surfaced to the UI. I'm pretty sure you can't get search to crawl them. – Rob Windsor Apr 3 '14 at 19:10
  • you are missing web.udpdate() add the property permanent – Mx. Mar 19 '15 at 12:48
0

I am adding a function to get property bag value and update setWebProperty function.

Set PropetyBag Value

function setWebProperty() {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_site().get_rootweb();
this.props =  web.get_allProperties();
this.props.set_item(“aProperty”, “aValue”);
ctx.load(web);
web.update();
ctx.executeQueryAsync(Function.createDelegate(this, setProperty),  Function.createDelegate(this, failedGettingProperty));
}

function setProperty() {
 alert(this.props.get_item(“aProperty”));
}

function failedGettingProperty() {
  alert("failed");
}

Get PropertyBagValue

function getWebProperty() {
   var ctx = new SP.ClientContext.get_current();
   var web = ctx.get_site().get_rootweb();
   this.props =  web.get_allProperties();
   ctx.load(this.props);
   ctx.executeQueryAsync(Function.createDelegate(this, gotProperty), Function.createDelegate(this, failedGettingProperty));
}
function gotProperty() {
   alert(props.get_fieldValues()["aProperty"]);
}
function failedGettingProperty() {
  alert("failed");
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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