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

IsEmpty not working

Hi

I run this OnVisible of my Home Screen:

 

If(IsEmpty(Filter(APM_User,Lower(UserEmail)=Lower(User().Email))),  --Check if email already exists

Patch(APM_User,{UserEmail:User().Email,Status: 1})                            --Add the record to the CDS entity

 

It should add a users email to the CDS Entity "APM_User" It should only add it if it does not exist.

The first part that check if the email exists does not work, the Patch never runs the CDS entity "APM_User" have no records.

 

Can you see anything wrong here?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino Community Champion
Community Champion

Re: IsEmpty not working

Hi @Jaco

 

There seems nothing wrong with your code (apart from a missing closing parenthesis at the end), but there are a few reasons why it may not work as expected, and my main candidate is the inefficiency of the User() function.

 

By the way, is there any reason you use the OnVisible and not the OnStart property for this?  I am asking this because even while designing the app, the OnVisible property will trigger when navigating to the home screen in Studio.

 

Going back to the problem with the User() functions, it is that they get called every time they are used, even though logically the user should never change during a session.  So I always cache the current user in a global record type variable as part of the OnStart property and then use the cached values in any subsequent code.  This avoids it being a null/blank value due to performance issues.

 

So I would try this for the OnStart property:

Set(CurrentUser, User());
If(IsEmpty(Filter(APM_User,Lower(UserEmail)=Lower(CurrentUser.Email))),  --Check if email already exists
Patch(APM_User,{UserEmail:CurrentUser.Email,Status: 1}))                        

If it still doesn't work, then just do this test:

If(1=1,  --Test
Patch(APM_User,{UserEmail:User().Email,Status: 1}))                         

View solution in original post

2 REPLIES 2
Meneghino Community Champion
Community Champion

Re: IsEmpty not working

Hi @Jaco

 

There seems nothing wrong with your code (apart from a missing closing parenthesis at the end), but there are a few reasons why it may not work as expected, and my main candidate is the inefficiency of the User() function.

 

By the way, is there any reason you use the OnVisible and not the OnStart property for this?  I am asking this because even while designing the app, the OnVisible property will trigger when navigating to the home screen in Studio.

 

Going back to the problem with the User() functions, it is that they get called every time they are used, even though logically the user should never change during a session.  So I always cache the current user in a global record type variable as part of the OnStart property and then use the cached values in any subsequent code.  This avoids it being a null/blank value due to performance issues.

 

So I would try this for the OnStart property:

Set(CurrentUser, User());
If(IsEmpty(Filter(APM_User,Lower(UserEmail)=Lower(CurrentUser.Email))),  --Check if email already exists
Patch(APM_User,{UserEmail:CurrentUser.Email,Status: 1}))                        

If it still doesn't work, then just do this test:

If(1=1,  --Test
Patch(APM_User,{UserEmail:User().Email,Status: 1}))                         

View solution in original post

Jaco
Frequent Visitor

Re: IsEmpty not working

Hi Meneghino

 

Thanks for your help, It is working fine Smiley Happy

 

Jaco

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

‘Better Together’ T-Shirt Contest – Winner Announced!

‘Better Together’ T-Shirt Contest – Winner Announced!

And the winner is...

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Power Platform 2020 release wave 1 plan

Power Platform 2020 release wave 1 plan

Features releasing from April 2020 through September 2020

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