Last active
December 13, 2017 16:38
-
-
Save Na0mir/9116893 to your computer and use it in GitHub Desktop.
Get SPWeb properties (property bag) using Javascript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------------- | |
// Author: Romain Blanchard | |
// Date: 20.02.2014 | |
// Description: Get SPWeb properties (property bag) using Javascript. | |
// ---------------------------------------------- | |
//Execute le script au chargement de la page, juste après le sp.js | |
ExecuteOrDelayUntilScriptLoaded(getAllWebProperty, "SP.js"); | |
var properties; | |
var propertyValues; | |
//Récupère toutes les propriétés du site courant. | |
function getAllWebProperty() { | |
var ctx = new SP.ClientContext.get_current(); | |
var web = ctx.get_web(); | |
this.properties = web.get_allProperties(); | |
ctx.load(properties); | |
// Requete asynchrone de récupération des propriétés. | |
ctx.executeQueryAsync(Function.createDelegate(this, getWebProperty), Function.createDelegate(this, failedGettingProperty)); | |
} | |
// Récupère une propriété en particulier. | |
function getWebProperty() { | |
this.propertyValues = properties.get_fieldValues(); | |
var SelectedPropertyValue = this.propertyValues["<PropertyKey>"]; | |
} | |
// Affiche une erreur si il est impossible de récupérer les propriétés du site courant. | |
function failedGettingProperty(sender, args) { | |
alert('Read property request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment