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
Power Apps Staff CarlosFigueira
Power Apps 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?

Power Apps Staff CarlosFigueira
Power Apps 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
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (7,944)