Friday, 28 April 2017

InfoPath Form: How to populate field on form load based on current user?


List One: Contains Account ID of the users and other fields.
List Two: Has the info-path form.

Customize List Two in InfoPath form:

Step 1. Create a connection to List One. Uncheck below option:

  • Store a copy of the data..
  • Automatically retrieve the data..
Step 2. Add a new rule under Form Load without any condition. Add 3 actions:
  1. Set a field's value:  Set the query field value for the above connection to filter the list item from List One. You can use userName() function to assign the value.
  2. Query using a data connection: Query for data from the above connection
  3. Set a field's value: Get the value from the data field  from the connection string and assign it to the form's field.
Note: The function userName() gives you only the Account id of the user. Something like i:0#.f|membership|user.name@company.com.

So, to get other details of the current user you can use the following web service:

https://hostsite/site/_vti_bin/UserProfileService.asmx

-OR-

Fetch the data from User Information List.


No comments:

Post a Comment