User experience is paramount in every application that you build. The application can be used in business operations, customer engagement, or even for personal use.
The experience you want and aim for is the personalization of the solution you are using and also for the end user. For instance “Welcome back User” sounds less personal than “Welcome back Shadrack”. This is why it is important to enhance this experience by displaying the username of the individual.
Power Apps is a component of the Microsoft Power Platform which is a low-code or no-code platform. It empowers developers and non-developers to create custom applications to enhance their business processes using custom and prebuilt components.
This platform is within the Microsoft 365 products, and you can be able to integrate it with a wide range of data sources such as SharePoint, Salesforce, SQL, etc.
One of the other benefits of using a username in Power Apps is at times multiple users need to access an application with different roles. Addressing the logged-in user by their username can help enhance the experience and also enhance access control.
This post will show you how you can use the User Function or Office365Users connector to display the user’s name.
User Function vs Office365Users Connector
In Power Apps, you can use both the User Function and Office 365 Users connector to retrieve the user information in your applications.
These two have different functionalities so you need to get to know the different use cases and capabilities.
User Function
This is a built-in function inside Power Apps that allows you to retrieve information about the currently signed-in User.
The information about the user that you are able to retrieve includes Full Names, Email, and their Image.
This function is used primarily to enhance the user experience based on the identity of the person logged into the application.
User()
The syntax for the User function has no arguments. The function returns results based on the context of the logged-in user.
Office365Users Connector
This is a connector specific to Power Apps which lets you access user profiles within the organization when you are building a Power Apps application.
You might be wondering what a connector is?
A Microsoft Power Platform connector is a way to connect other services to the Power Platform. For instance, if you need to access external databases or API endpoints, you can build a connector from the API and then use it in the Power Platform.
The Power Platform has thousands of connectors available.
The syntax for Office365Users Connector is the following.
Office365Users.MyProfile()
Let’s have a breakdown of the formula here
- Office365Users refers to the connector in Power Apps that lets you interact with Microsoft 365 services which includes user profiles.
- MyProfile function is used to fetch the profile data associated with the authenticated user.
📝 Note: Unlike the User function, you need to enable the Office365Users connector first before you can use it!
How to Add the Office365Users Data Connector
To enable a data connector, create a Power Apps application. Navigate to the data tab as shown below and search for the data connector you want to use. For our case, you will use the Office 365 User Connector
Follow these steps to add a data connection to your app.
- Go to the Data tab on the left menu pane.
- Click on the Add data button.
- Search for the data connector you want to add. In this case, search for Office 365 Users connection.
- Click on the Office 365 Users connection from the list.
This can also be accessed from the main Power Apps ribbon where you can find the Add data command.
Once you have selected the option, you will get a prompt to connect and your data connection will be created.
How to Get Full User Name
For the next steps, you will delve into the world of enhancing the user experience in Power Apps by using the User Function and the Office 365 Users connector.
This guide will show the areas outlined below.
- How to get the Full Name of the user.
- How to get the First Name of the logged-in person.
- How to get the Last Name of the logged-in user.
You will see how to each of these with both the User function and the Office365Users connector.
Using User Function
As mentioned earlier you will be using the basic syntax of the User Function to retrieve the username of the person logged in to the Power Apps.
You will be using a text box in Power Apps to show the username of the person. For your application, you will need to add a text box.
To add a text box label to your application you will need to follow these steps. The text label will enable you to add the formula to display the username of the logged-in user.
- Go to Insert Tab on the left menu pane on your application.
- Click on the Text label from the list under the popular dropdown.
- Once you have added the Text label property, by default it will have the Text property, you will replace this with your formula.
- The Text Label will now be added to your Canva application.
After you have inserted the text box, you will add the formula of the User function on the formula bar. This will be used to add the formula of the User function and also for the Office365Users connector.
User().FullName
The above formula will return the user’s full name.
"Welcome " & User().FullName & "!"
With this, you can now customize the label and add other functionality such as the above welcome message formula.
Using Office365Users Connector
For the Office365Users connector, you will be adding the connector as highlighted in the previous section.
Office365Users.MyProfile().DisplayName
Once you have added the connector, you can use the above formula in your text label to return the user’s full name.
Getting the First Name of the User
Using User Function
At times you need to only display the First Name of the person who is logged in.
First(Split(User().FullName, " ")).Value
The above formula will display only the first name.
This is the breakdown of this formula to help you understand how it works
User().FullName
returns the users full name.Split(..., " ")
splits the Full Name into an array based on the space character.First(...)
is used to select the first element from the array that resulted from the Split function. This will be the first name..Value
will be able to take the value from the record that theFirst(...)
returns. This accesses the text value of that record.
Using the Office365Users Connector
For this section you will also be implementing the same using the Office365Users connector.
The prerequisites for this is to ensure you have already connected your Power Apps application.
Office365Users.MyProfile().GivenName
The above formula will return the users first name.
Adding the .GivenName
property will give access to the given name of the user’s profile!
Getting Only the Last Name of the User
You have already seen how to get the full name, and first name. Now you will be able to get the Last Name of the person logged in to your Power apps using the approach of the User function and also the Office365Users function.
Using the User Function
Last(Split(User().FullName, " ")).Value
For this, you can use the above formula.
This formula is more similar to getting the first name.
The major difference is you will be using the Last(...)
function. This function selects from the last part of the array that was split and this contains the user’s last name.
Using the Office365Users Connector
Office365Users.MyProfile().Surname
At times you will also want to use the Office 365 Users connector to achieve the same functionality. The above formula will do this.
Using the .Surname
will be able to retrieve the surname of the person. This is the last name.
Conclusions
Creating the user experience is really important and you have just explored two ways in which you can get user information.
You can use the User function as well as Office365Users connector. These two are like magic tools that let you see who is using your app.
These special tools create connections with users. You have also seen the difference between the User function and Office365Users connector and learnt how to add a data connector to your app.
Whether you are new to making apps or a pro, these tricks can help you create long-lasting impressions with your users.
Have you used these techniques to get the user name in your apps? Let me know in the comments.
0 Comments