Using the SharePoint 2013 REST user resources API in InfoPath 2013

I recently did a DB attach migration from SharePoint 2007 to 2010 to 2013 for a customer, which requires many steps to account for all the changes in SP along the way. One of the changes that I chose to make was to replace some of the older SOAP web services calls, like GetUserProfileByName, in InfoPath forms converted from 2007 to 2013. I started with the approach outlined in John Liu’s post here. John’s post takes care of the on-the-fly changes often required to REST URLs to use them for a specific query without resorting to a whole set of Data Connections for each required query. The other necessary information is in the SharePoint REST API spec, specifically here for the User resource specifications.

Essentially the URL for this query takes the form of

http://<web app URL>/_api/siteusers(@v)?@v='i%3A0%23.w%7Cdomain\userid

For example, for an on-premise 2013 installation, the URL might look something like this:'i%3A0%23.w%7Cmicrosoft\rramirez'

Invoking this query will result in a ATOM-XML feed returning that can be used in InfoPath to select particular fields of interest. Below is an example of such an XML document.

 <?xml version="1.0" encoding="utf-8" ?> 
 <entry xml:base="" xmlns="" xmlns:d="" xmlns:m="" xmlns:georss="" xmlns:gml="">
 <category term="SP.User" scheme="" /> 
 <link rel="edit" href="Web/GetUserById(1209)" /> 
 <link rel="" type="application/atom+xml;type=feed" title="Groups" href="Web/GetUserById(1209)/Groups" /> 
 <title /> 
 <name /> 
 <content type="application/xml">
 <d:Id m:type="Edm.Int32">1209</d:Id> 
 <d:IsHiddenInUI m:type="Edm.Boolean">false</d:IsHiddenInUI> 
 <d:Title>Russ Ramirez</d:Title> 
 <d:PrincipalType m:type="Edm.Int32">1</d:PrincipalType> 
 <d:Email /> 
 <d:IsSiteAdmin m:type="Edm.Boolean">true</d:IsSiteAdmin> 
 <d:UserId m:type="SP.UserIdInfo">

The data of interest in one particular case was the value within the <Title> element; this is equivalent to the PreferredName field returned using the GetUserProfileByName() web method. Within InfoPath then, you just need to do the following:

  • Define a Data Connection to a simple REST URL like
  • Create a Form Load rule that will
    1. do a Change REST URL Action
    2. do a Query of the REST data connection (it will use the new URL just modified)
    3. set the value of the field of interest; e.g. a Prepared By field

The XPath for the Change REST URL action of step 1. will look like this for our example:

concat("'i%3A0%23.w%7Cmicrosoft\", my:UserId, "'")

The escaped characters in the variable @v are i:0#.w| which you should recognize, and the my:UserId is a field in InfoPath initialized to substring-after(xdUser:get-UserName(), “\”) so the user id part (rramirez in this example) is stored for use by the modified REST URL. If you try this URL from a browser (turn off Feed view in IE), you will get the XML document above with your pertinent information. Step 3. above, setting the Prepared By field, uses the value of the Title element as I mentioned. Here’s what the REST service schema looks like in InfoPath 2013: RESTschema Once you have done all of this, you should see your user’s preferred name/title looking like this: prepared by field


About generation12

I am a SharePoint/.NET consultant in the twin cities.
This entry was posted in GetUserProfileByName, InfoPath 2013, REST, SharePoint 2013. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s