Step 1 – create the second data connection
Create the second data connection to the User Profile service
Click the Data tab on the ribbon, and then select Data Connection. The "Data Connections" dialog box appears. Choose "Add".
Create a new connection to: Receive data – Next>
Where do we want to get the data from: SOAP web service
Enter the location http://yourserver.com/_vti_bin/UserProfileService.asmx?WSDL – Next>
Select an operation: "GetUserProfileByName" – "Next"> "Next"> "Next" (make sure that "Save a copy of the data in the form template" is deactivated).
Give the data connection a name – I named my "Get User Manager Details" (note: also make sure that "Get data automatically when the form opens" is not selected)
The second data connection has been established and can now be used to retrieve the manager information.
Step 2 – the mgrAccountName field
Create a field in the main fields – under myFields – and name it mgrAccountName. Right click on myFields and select Add to add the field
Add a default value to the mgrAccountName field over the first data connection (mine is GetUserProfileByName).
– Open the field or group properties for the "mgrAccountName" field and click the "Fx" button to the right of the "Value" field.
– The Insert formula dialog box opens. Select Insert Field or Group.
– Activate the dropdown field under "Fields" in which "Main" is selected and select "GetUserProfileByName". Then click on the plus sign (+) next to "dataFields" and click on the plus sign (+) until there is no symbol (+) left to open. You will see the Value field.
– Select the Value field and click the Filter data button
– When the "Filter data" field opens, click "Add". The "Specific filter conditions" option opens
– Starting from the left – Click on the dropdown box and change the value to "Select field or group". – When the Select field or group field opens, select Name. Then click OK
– The name must be "is equal to" manager.
– Click on the last dropdown box on the right and select Enter text…. and enter manager. Click OK repeatedly until all fields are closed.
The end result is a default value of: Value (Name = "Manager") for the field "mgrAccountName".
By default, the field is the manager account name of the logged in user.
- Next we have to add an action to the mgrAccountName – this sets the field value for the data connection "Get User Manager Details" to the value (mgrAccountName) – mmmm … just follow and observe
– Select the mgrAccountName field in the main fields, right-click and select Rules.
– Under Rules, click the New button to create a new rule for the mgrAccountName field. Then choose Action. The action is "Set Field Value". So under Rules, click the Add button, and then click Set Field Value.
– Field: Click the button on the right and select the field from the data connection "Get Users Manager Details".
– Under myFields click on the (+) symbol next to queryFields – and then again under for the next folder – you should now see AccountName – select this and click OK
– Value: Click the Fx button on the right and then click Insert field or group. In the main fields, select the current field (mgrAccountName). Click OK. Close all open fields.
Step 3. The Manager's Full Name field
Create a new field (if you don't already have one) in the main fields. I named my usersMgrName
In the fields, change the Main entry to Get Users Manager Details.
– Expand the query fields by clicking on the (+) symbol. – Change to the next folder until the AccountName field is displayed. – Select this field.
– With the Account Name field selected, click the Home tab on the ribbon and then click Manage Rules to add a new rule to the Account Name field. Click New to create the new rule.
We will create two actions, one to query the data connection and the other to set the usersMgrName field.
– Action 1: Select "Add" and then "Query data". Ensure that the data connection "Get user manager details" is selected in the rule details. Click OK".
– Action 2: Select "Add" and then "Set field value". In the field, select the new field that you created for the manager's full name. My name was "usersMgrName".
For the Value field, we need to get the PreferredName data based on the selected manager. To do this, click the Fx button on the right. The Insert Formula field is displayed.
– Click "Insert Fields or Group" and select the "Get User Manager Details" connection from the list of fields. – Expand "dataFields" completely until you can no longer expand.
– Select the "Value" field in the "ValueData" directory and click on "Filter data".
– Click the Add button". Then in "Set filter conditions" click on the first dropdown box on the left and select "Select field or group …".
– In the connection data source "Get Users Manager Details" select the entry Name. – Click OK
– In the drop-down box on the far right under Specifiy Filter Conditions, select the Type text option and enter PreferredName. Click OK, and then click OK
– You should now see the formula – Value (Name = "PreferredName") – Click OK to finish – and then click OK again.