cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

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

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?

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

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

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