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.
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
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.