Canvas Apps Expressions

Working with Office 365 User Display Names

For anyone working with Office 365 user display names, it is commonly known that different organisations have different formats. For various reasons, it may be desired to fetch the user name in one of the more standard formats like First Name Last Name or Last Name, First Name.

Let's say my display name is in the format Last Name, First Name, City, Department, Title, i.e. Bhatia, Hardit, Houston, Consulting, Architect. The two desired formats we will review are Last Name, First Name and First Name Last Name.

Office 365 display names can be fetched using:

Office365Users.MyProfile().DisplayName

Format #1: Last Name, First Name

Label_DisplayName is where my display name is in the original format. The following formula will result in the display name in format #1:

Left(Label_DisplayName.Text,Find(",",Label_DisplayName.Text,Find(",",Label_DisplayName.Text)+1)-1)

The first Find function from right returns a value of 7 which is the position of the first comma after my last name Bhatia. The next Find function searches for the position of a comma starting from position #8 (7+1). It returns a value of 15 which is the position of the comma after my first name Hardit. Finally, the Left function returns the beginning 14 (15 -1) characters which is Bhatia, Hardit.

Format #2: First Name Last Name

For simplicity, let's assume that the above formatted display name is stored in a variable Format1Name. The following formula will result in the display name in format #2:

Last((Split(Format1Name, ","))).Result & " " & First((Split(Format1Name, ","))).Result

The primary function used here is Split. It splits a string based on the specified character and returns a table of the substrings. The table returned here has two values: Bhatia and Hardit. The Last function returns the first name Hardit and the First function returns the last name Bhatia. Finally a space is added in between to get the desired format.

While your Office 365 display names may be in a completely different format, hopefully this post will help you to use these functions to fetch the display name in the desired format.

Have fun! Get addicted!

Leave a Reply