0

I have an approval flow that updates a field after an outcome with the name of the approver. The field name is Approver. Its a single line text field.

What I'm trying to do is check to see if the name in the Approver field(display name) matches the current logged in user viewing the item. The container should stay invisible unless the display name matches the name in the "Approver" field.

This is the function statement:

If(Office365Users.MyProfile().DisplayName=DataCardValue,true,false)

DataCardValue is the value field of the approver data card.

2 Answers 2

1

You can use below simplified formula in Visible property of your container or other controls in Power Apps (use latest MyProfileV2 function instead of MyProfile):

DataCardValue.Text = Office365Users.MyProfileV2().DisplayName

Where DataCardValue is the name of your Text or Label control in Power Apps.


Additional Info to improve performance:

If you are using Office365Users.MyProfile() function at multiple places in your application, you can set one variable in App.OnStart to store the user profile instead of calling Office365Users API every time. Like:

Set(gvUserObj, Office365Users.MyProfileV2());

Then use conditions like for below for multiple controls:

DataCardValue.Text = gvUserObj.DisplayName

Also, try using approver user "email" property to match in conditions instead of display name if possible. Two users in the company may have same display names sometimes.

2
  • I'm taking your advice and using email instead but something odd happens. When i play it from inside of canvas it works as expected hiding the section and only displaying it when my email is in the field. That said its not working on the form directly on the list. This is the formula I'm using: If(DataCardValue26.Text = Office365Users.MyProfileV2().mail, true, false)
    – Mile T.
    Commented Nov 6, 2023 at 23:25
  • Ideally this should work: DataCardValue26.Text = Office365Users.MyProfileV2().mail. Can you try using this: DataCardValue26.Text = User().Email? Make sure text in DataCardValue26.Text is exact same as user email (case sensitive). Commented Nov 7, 2023 at 6:28
0

My function was off just a little bit. The way to get it to work is with a function that looks a bit like this.

If(DataCardValue.Text = Office365Users.MyProfile().DisplayName, true, false)

Change the "DataCardValue" to match the card value name you have in your form. Additionally the field you get the value from is you don't want your function to fail, you may want to set it to view only.

1
  • 1
    No need to use If and true false as the test (=) already returns a Boolean!
    – jleture
    Commented Nov 3, 2023 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.