Sometimes people ask me why I’m still bothering with the crufty old SOAP Web Services in SPServices. After all, there are REST and CSOM to play with and Microsoft has decided to deprecate the SOAP Web Services.
Well in some cases, the Shiny New Toys don’t let you get the job done. In cases where you’re implementing on Office365 and simply can’t deploy server side code, SPServices can sometimes be just the right tool. It’s easy to use and it gets stuff done that you need. What more can I say?
I found this nice story from Gary Arora about updating User Profile data a few weeks back. In it, Gary shows us how to easily make those updates on Office365 using SPServices. Gary calls himself “your friendly neighborhood SharePointMan” and he is happy to be have his story be one of my stories.
The Use Case
SharePoint 2013 users need to modify (specific) user-profile-properties client-side without having to navigate away to their ‘MySite’ site and swift through rows of user properties.
(Following is an mock-up showing a simple interface to update a user profile property via CEWP)
Simple interface to update Fax number from a CEWP. (Basic demo)
The Usual Solution
In the SharePoint 2013 universe there are 2 ways to read/write data client-side. CSOM and REST. Unfortunately CSOM and REST are not fully there yet when it comes to matching the server side functionality.
In this specific case, one could use CSOM or REST to retrieve (read) User Profile Properties but there is no way to modify (update) these properties from client-side. Here’s Microsoft’s official position.
Not all functionality that you find in the Microsoft.Office.Server.UserProfiles assembly is available from client APIs. For example, you have to use the server object model to create or change user profiles because they’re read-only from client APIs (except the user profile picture)
Hence The Dirty Workaround
So our workaround is SOAP, the forgotten granddaddy of Web services. The User Profile Service web service, from the SharePoint 2007 days, has a method called ModifyUserPropertyByAccountName which functions exactly as it sounds. But since SOAP can be a bit intimidating & ugly to write, we’ll use SPServices, “a jQuery library which abstracts SharePoint’s Web Services and makes them easier to use”
So here’s how we’ll use SPServices to modify User Profile Properties. The method is applicable to SharePoint 2013 & 2010 (online & on-prem) versions.
1. Reference SPServices library
You have two options here. You can either download the SPService library and reference it locally or reference it from its CDN:
Note: The above code works but notice that you are passing a hardcoded userId.
To pass the current userId dynamically, we can use CSOM’s get_currentUser(). But since that’s based on the successful execution of ClientContext query, we need to “defer” invoking “updateUserProfile()” until we have received current userId. Therefore we’ll create a Deferred object as follows:
You can only edit the user profile properties that are editable (unlocked) on your MySite. Certain fields like department are usually locked for editing as per company policy
Can you help me in updating custom user profile property of type – String (Multi Value)
mapped to term store.
I’m able to update it using single term, but when I pass multi term it gives 500 error.
Hi there, does this work with on-premises SP2013?
Miikka:
This should work exactly the same on premises.
M.
Hi Marc,
Can you help me in updating custom user profile property of type – String (Multi Value)
mapped to term store.
I’m able to update it using single term, but when I pass multi term it gives 500 error.
I tried below options:
1) Term1,Term2
2) Term1;Term2
3) Term1|Term2
4) TermName1;#GUID1,TermName2;#GUID2
But, no luck.
Could you please suggest?
Whenever i try to update the property , it says “the specified property does not exist” but in user profile property exist and modifiable also