How to create web properties on SharePoint hosted apps.


Hi Guys,

Here i can explain how to create and use web properties on SharePoint hosted apps.

To create the proprieties use the below code.

/*********Function to create web properties ********/

function createProperties() {
appContextSite = new SP.AppContextSite(issueContext, hostWebUrl);
hostWeb = appContextSite.get_web();
issueContext.load(hostWeb);
issueContext.executeQueryAsync(oncreateIssuePropertiesSuccess, oncreateIssuePropertiesFail);
}

// This function is executed if the above call is successful
function oncreateIssuePropertiesSuccess() {
issueContext = new SP.ClientContext(appWebUrl);
var factory = new SP.ProxyWebRequestExecutorFactory(appWebUrl);
issueContext.set_webRequestExecutorFactory(factory);
appCtxSite = new SP.AppContextSite(issueContext, hostWebUrl);
currentWeb = appCtxSite.get_web();

var webProperties = currentWeb.get_allProperties();
issueContext.load(webProperties);

webProperties.set_item(“Key”, “Value”);

currentWeb.update();
issueContext.executeQueryAsync(onPropertyRegisterSuccess, oncreateIssuePropertiesFail);

}

To get the property value use the below code.
/*********Function to read web property values ********/
function readIssuePagesProperties() {
webProperties = hostWeb.get_allProperties();
issueContext.load(webProperties);
issueContext.executeQueryAsync(ongetWebPropertiesSuccess, onRegisterFail);

}

/*********Function to read web property values ********/
function ongetWebPropertiesSuccess() {

//make sure the property is there before using it.
if (webProperties.get_fieldValues().Key != undefined) {
keyValue= webProperties.get_fieldValues().Key;
}

}

Cheers!!!!!!

About Suresh Nakka

Hi This is Suresh working as SharePoint developer.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment