cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Power Apps
Power Apps

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
Highlighted
Frequent Visitor

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?

Highlighted
Power Apps
Power Apps

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

Highlighted
Frequent Visitor

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
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,882)