0

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();
}
  • Can you show the JSOM code please? – Cann0nF0dder Mar 26 '14 at 10:28
  • When you get the onRequestSuccess() try getting the result personProperties.get_userProfileProperties()['PaidUser'] – Cann0nF0dder Mar 26 '14 at 10:43
  • Its one and the same, anyways I tried it. No good news – variable Mar 26 '14 at 10:53
  • Sorry. It must have something to do with your import process then, nothing to do with the code. – Cann0nF0dder Mar 26 '14 at 11:35
  • You did not understand the question, please read again. I have updated with some correction, maybe will give you better picture. – variable Mar 26 '14 at 11:36
1

When working with the User Profile Service you will find that uninitialized values are not sent via REST. Your code has to account for the fact that the user may "opt out" and not populate a value. In your code determine if the value is present and if not, determine the default, in your case "false". I like to believe that this is an "optimization". :)

  • Is there any way we can set a default to true/false ? Just asking. – variable Mar 28 '14 at 4:13
  • Not that I have seen. Though I have not tried. – Matthew McDermott Mar 28 '14 at 11:24

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.