cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
sotomo
Level: Powered On

How to handle asynchronous binding of text labels

I have a list of users stored in a database, and need a label populated with...

 

"This user is not registered"

 

...whenever the user doesn't exist in the database table.

 

So the Text attribute of the label has the code:

 

If(LookUp('[dbo].[Users]',EmailAddress = Email.Text, ID)=Blank() ,"User is not registered.","")

 

The problem is that the application populates the field with "User is not registered." for a few seconds before the LookUp function is finished.  It is either waiting for the DB lookup or for the Email label to populate with User().Email.

 

Presumably, since the user has not yet been looked up, it appears to the app that the user does not exist (until it is found).  I'm accustomed to "synchronous" methods in C# that wait until the DB query is done before populating a field, so I don't know how to make sure the field stays blank until the LookUp is finished. 

 

How can I make the label stay blank until LookUp is complete?

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: How to handle asynchronous binding of text labels

You can use a variable to hold the value of the label that you want to display. The initial value of the variable would be empty, and it would be set when the result of the LookUp expression is available. For example, you can have this expression in the OnVisible property of the screen where this is shown (or in the OnStart property of the app):

Set(errorMessage, "");
Set(userEmail, User().Email);
If(
    userEmail <> "",
    If(
        IsBlank(Lookup('[dbo].[Users]', EmailAddress = userEmail, ID)),
        Set(errorMessage, "User is not registered with this application."))

And you can set the Text property of that label to

errorMessage

View solution in original post

3 REPLIES 3
sotomo
Level: Powered On

Re: How to handle asynchronous binding of text labels

More information, there seems to be some improvement when I change the code to:

 

If(IsBlank(Email.Text),"",If(LookUp('[dbo].[Users]',EmailAddress = Email.Text, ID)=Blank() ,"User is not registered with this application.",""))

 

Email.Text is populated with User().Email

 

But "User is not registered with this application." still flashes for like a tenth of a second, probably until the DB read is complete. 

 

Is there a solution to this problem?

PowerApps Staff CarlosFigueira
PowerApps Staff

Re: How to handle asynchronous binding of text labels

You can use a variable to hold the value of the label that you want to display. The initial value of the variable would be empty, and it would be set when the result of the LookUp expression is available. For example, you can have this expression in the OnVisible property of the screen where this is shown (or in the OnStart property of the app):

Set(errorMessage, "");
Set(userEmail, User().Email);
If(
    userEmail <> "",
    If(
        IsBlank(Lookup('[dbo].[Users]', EmailAddress = userEmail, ID)),
        Set(errorMessage, "User is not registered with this application."))

And you can set the Text property of that label to

errorMessage

View solution in original post

sotomo
Level: Powered On

Re: How to handle asynchronous binding of text labels

That works great.  I guess doing things outside the Text property tends to be more sequential.  Thanks.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 185 members 5,418 guests
Please welcome our newest community members: