This project has moved and is read-only. For the latest updates, please go here.

How to Write to a User Profile Property

Aug 13, 2012 at 6:20 PM
Edited Aug 14, 2012 at 3:45 PM

My requirement write to (update) a value of a custom user profile property. It's a custom zip code property that we will use to let the user set a weather webpart.  What function should I be looking at?

I tried using the ModifyUserPropertyByAccountName function as Karel mentioned here but it's failing to update the User Profile property.

Code to follow...

Aug 14, 2012 at 3:34 PM
// profile properties that are pulled in from active user
var thisUsersID;
var thisUsersCustomPostalCode;
// hardcoded values for testing
var zipPropName = "UserPostalCode";
var zipPropValue = "12345";

$(document).ready(function() { 
    $(".pp-ButtonWrap").append("<span class='gaView'><a href='#' onclick='modUserZip(thisUsersID, zipPropValue)'>Update Zip</a></span>" );

//Start user profile property update function 
function modUserZip(thisUsersID, zipPropValue){
	var propertyData = "<PropertyData>" +
"<IsPrivacyChanged>false</IsPrivacyChanged>" +
"<IsValueChanged>true</IsValueChanged>" +
"<Name>UserPostalCode</Name>" +
"<Privacy>Public</Privacy>" +
"<Values>" +
"<ValueData>" +
"<Value xsi:type=\"xsd:string\">" + zipPropValue + "</Value>" +
"</ValueData>" +
"</Values>" +
operation: "ModifyUserPropertyByAccountName",
		async: false,
		//webURL: "/_vti_bin/UserProfileService.asmx",
		accountName: thisUsersID,
		newData: propertyData,
		completefunc: function (xData, Status) {
			var result = $(xData.responseXML);
			alert("wierd one" + result);
	alert("UserPostalCode = " + thisUsersCustomPostalCode); 

//get various profile properties of current users
function getUserProfileProperties() {
	thisUsersID = $().SPServices.SPGetCurrentUser({fieldName: "ID"});
	thisUsersCustomPostalCode = $().SPServices.SPGetCurrentUser({fieldName: "UserPostalCode"});
It's a simple example but it fails.  
A few things to note is that at the "weird one" alert, I'm getting back an [object] [object] value.  
I also thought it may have to do with the fact that I'm using a custom user profile property instead of an out of the box one; not the case. It's busted with both.
Any thoughts or suggestions?
Aug 14, 2012 at 3:38 PM
Edited Aug 14, 2012 at 3:39 PM

Two more things of note about the above example:

1. The webURL is commented out b/c I was testing on the root.  Would I still need a WebURL attribute here?  If so, would it point to central admin since that's where user profile properties live? 

2. The type of my custom column is string even though I'm plugging in a number.

3. I also ensured my custom property is "replicable", although I'm not sure if it matters.

Aug 16, 2012 at 2:18 AM


My mistakes were two fold:

1. I was passing the userID instead of the "Name" property

2. I was testing, coding, testing, coding...  but I never pushed the user profile timer job... duh.  There's a quick Sync and a full sync defaulted to minutes and hours respectively.

And to answer myself from above, if it lives on the root, no WebURL is needed.

The next problem I'm running into is trying to update a user profile property with a type of multi-value string.  Any thoughts? Or will this continue to look like I'm talking to myself?

Aug 17, 2012 at 12:05 AM


I wasn't getting any alerts this week until tonight. I thought things were a little quiet.

Sounds like you are making good progress. The best way to determine what a User Profile field value should look like for an update is to read an existing value and see how it's formatted. Especially in the case of fields your organization may have created, that's probably the most reliable route.


Nov 20, 2014 at 2:38 PM
Did you manage to find a solution about updating the multi-value string ?