Cleaning Up UserName() Function using Infopath

Copper Contributor

I have an InfoPath form published to Office 365, SharePoint Online, which uses the UserName() function to identify the creator of the instance as the project owner.

 

For Example:

i:0#.f|membership|lwilliam@abc.com

 

I want to display only "lwilliam" to my infopath form. I don't need the rest of unnecessarily item. 

 

I just tried using : substring-after(userName(), "i:0#.f|membership|"), but the result is "lwilliam@abc.com".

1 Reply

Is there a reason you want just part of an email and not their actual name? There is a great post on how to retrieve various user information: https://www.qdoscc.com/blog/how-automatically-retrieve-current-username-infopath-sharepoint-list-for... 

 

If you don't mind "helper" fields that you hide on the form you can always have two fields.  One named "emailAddress" that says: substring-after(userName(), "i:0#.f|membership|")

 

And the second could be the field you want by putting in: substring-before(emailAddress, "@abc.com")  

 

You would end up with an extra field that you could hide, but it should get you the end result that you are looking for.  You could also use the post listed above and choose WorkEmail instead of PreferredName and put in in this formula instead of emailAddress: substring-before(<follow post directions here>, "@abc.com")

 

Tim