When designing Office 365 InfoPath forms, it is a common requirement to have the form automatically capture and display the name of the person who is submitting the form. InfoPath 2010 has a built-in function userName() that returns the Account ID of the authenticated user. This ID can be used to find and display a user’s name in a text box or calculated value control. If the form is to be published to SharePoint and filled using a browser-based form, the current user’s name also can be captured by using the GetUserProfileByName web service in conjunction with the Current User filter web part. The name displayed is usually in the “Preferred Name” format, which in most cases consists of a first and last name. All of this works like a charm with on-premises SharePoint, but when publishing your form to the cloud, the display of the username will be in forms-based format, which combines the string ” i:0#.f|membership|” with the user’s email address. (See Fig 1-1)
From a usability perspective, this format is not convenient and to most clients it will prove unacceptable. A little research into this issue showed that there are two ways to resolve this. One is to submit a ticket to Office 365 support and the other is to remove the Lync licenses for each user, wait 24 hours until the User Profile Service is run, and add back the licenses. Both of these methods involve significant expenditure of time. So if time is scarce, and you don’t mind quick and dirty, I will show you a third way.
In most organizations, email naming schemes follow a pattern that makes it relatively easy to know who the email address belongs to. If this is case in your organization, then displaying the email address of the user filling out the form should suffice. This can be done by adding a field to your form that basically copies the text returned by the username() function and truncates it using InfoPath’s substring-after method. (See Fig 1-2)
The substring-after method takes two arguments: the first is the full string to be modified, and the second is a substring that identifies the point in the full string where the split will occur. The first argument in this case can be set to the original username field by using the “double-click to insert field” link in the formula or the “Insert Field or Group…” button below. (See Fig 1-3) In the example below we used a substring that includes all the text before the email address, but any unique segment of text such as “|membership|” could have been used and everything before the substring would be removed including the segment itself.
Once the formula is in place, you can convert the new username field to a calculated value and test it out. After the testing is complete, hide the original username field by using Form Load rules. Your original forms-based username field has been replaced by a readable, user-friendly email address! (See Fig 1-4)