We are using user profile AD import. We have created 2 new custom user properties of type Boolean.
When fetching the value for a custom property via JSOM, the value comes as "".
The value of the property can be retrieved successfully only if you change the user profile property via UI before fetching it via JSOM.
Now our site has 1000 users. The problem is that, we will have to manually go to each user profile and check/uncheck the value of this property which is not feasible.
Is there any programatic or other solution in which we can specify that it is 'false' for all users?
Code that works (MSDN code) :
var personProperties;
// Ensure that the SP.UserProfiles.js file is loaded before the custom code runs.
SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js');
function getUserProperties() {
// Get the current client context and PeopleManager instance.
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
// Get user properties for the target user.
// To get the PersonProperties object for the current user, use the
// getMyProperties method.
personProperties = peopleManager.getMyProperties();
// Load the PersonProperties object and send the request.
clientContext.load(personProperties);
clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
}
// This function runs if the executeQueryAsync call succeeds.
function onRequestSuccess() {
alert(personProperties.PaidUser());
}
// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
$get("results").innerHTML = "Error: " + args.get_message();
}