I have requirement to switch the views based on the user opening the form.There are set of user list maintained in a SP list and these values are added to the drop down list through data connection in the infopath. And using the GetUserProfileByName, the current user name is retrieved and put it into a text box field on form load. But on form load, When I am trying to compare the value in the text box field to the drop down list values, it is not working. Is it required to iterate through all the values of the drop down list to compare against each value? or is it taken care. In case if it needs to be iterated, Please suggest any solution. need only out of the box solutions.

1 Answer 1


You don't need to write the user name into a text field. In the SharePoint list of people make sure to have a field "UserID" that stores the person's name in the same format as it is returned by the Infopath username() function.

With that in place, create a new data connection to read data from that SharePoint list. Include the UserID field in the data connection.

Now create a rule for Form Open. In the data connection mentioned above, open the + next to the query field and set the UserID in the query field section to username(). Next, query the data connection.

If the UserID is found in that SharePoint list, the data connection's ID field will not be empty, so you can create a rule with the condition that the data connection "ID is present" and use an action to switch to the desired view.

  • I understood till creating a data connection to the list. Could you please provide with more details on the next steps you have mentioned on form opening and all.
    – user38433
    Oct 3, 2016 at 6:28
  • Look here. If you have managed to get the current user name with GetUserProfileByName, then a simple data connection to a SharePoint list shouldn't be all that hard. I edited the answer with more details.
    – teylyn
    Oct 3, 2016 at 8:03
  • On Form load, I have set the UserID field in the query section of the data connection to Username(), Then , again on form load itself I have added under action - Query Using data connection adding this data connection there. In the next rule, checking ID is present. But t is not working for me. It i switching to that respective view.
    – user38433
    Oct 3, 2016 at 10:04
  • Check your data and check what the query returns: Drag the data connection fields on the canvas so you can see what is returned by the query. Make sure the UserID field in the SharePoint list has exactly the same content as what the UserName() function creates. Test with your own user name.
    – teylyn
    Oct 3, 2016 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.