In this article, I’m going to demonstrate how to get the current user’s manager’s information.
We all know the usage of userprofileservice.asmx in InfoPath 2010 and how we can extract data for the current user using this web service. But what if we want to get information for user’s manager, like first name and last name. In this case we need to add a second data connection, this data connection is going to behave as a source to get manager information. To do this, click Data from the ribbon, then add data connection to userprofileservice.asmx and getuserprofilebyname , call it Profile Second Connection.Now we will have these 2 data connections in the data connection section in InfoPath 2010 as the following:
Add a field to the main data source call it manageraccountName, you do this by right clicking on the myFields folder in the right pane, and add a field, and use the Profile First Connection to get the manager account name into this field, you do this by opening field’s properties, click the Fx button next to default value, click insert Field or Group, Change the data source to Profile First Connection, Expand the data fields until you reach the value field, click one click on the value, and click filter data, in the filter data popup, click add, change the left dropdown list to “Select a field or group”, in the select field or group popup choose the “Name” field, click OK, in the right dropdown list write “Manager”, and click OK for everything.
Second step is to put action on this manager field, this action is going to set the field value for the Profile Second Connection to its value. It’s a complex process but follow my steps literally.
Click on the manager account name field, click manage rules, add a new rule and make an action inside it, the action is of type Set a Field’s value, for the field click on the button to choose the field, from the data connection drop down list as in the following picture:
choose the Profile Second Connection, Expand the queryFields and the group below it, and choose AccountName, Click OK, see the below picture:
In the Value field, click the Fx, click insert field or group, and choose current field (manageraccountName).
Now that you have set the value for the accountname in the Profile Second Connection to the managerAccountName, do the following steps:
1- Add new field to main data source, called managerFirstName.
2- In the data source, change the data connection to Profile Second Connection, Expand the queryFields, then the group under it, and click AccountName, then click manage rules, Add action rule.
3-The first action will Query the Profile Second Connection,
4-The second action will set the field managerFirstName, to the value of the Profile Second Connection value where property name = FirstName, as we always do with the current user when we get his information.
See the following 3 Screenshots:
Select managerFirstName from the set field’s value wizard:
Choose the second data connection for the value of the field, click value, then click filter data,
In the filter data, choose the Name from the wizard, and type FirstName, this will get the manager’s first name.
Hope this helps people out there.
Updated: Added Screenshots as requested in the comments.