web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to do a conditiona...
Power Apps
Answered

How to do a conditional statement for updating an record or creating a new record based on user's email existing in underlying data?

(0) ShareShare
ReportReport
Posted on by 383
If(IsBlank(LookUpEmail), Patch(DataSourceName, LookUp(DataSourceName, 'Customer Email'=User().Email), FormControlName.Updates), Patch(DataSourceName, Defaults(DataSourceName), FormControlName.Updates))

 

In the above, I am trying to create an If statement so that if the user email exists already in the underlying data, the record is updated, if not, it creates a new record. This is typed in the "On Select" for a save button to save the information on a form control.

 

It updates an existing record! But it's not creating a new record if there is no existing email in my data source with the IF statement. The different patch functions for updating an existing record or creating a new record both works separately, but not together in the IF statement. I have no errors in my code. Again, it is only updating an existing record when I do the IF statement, but the Patch functions both work separately outside of the IF statement. 

 

Any insight on what I am doing incorrectly would be appreciated.  

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    155,679 Most Valuable Professional on at

    Hi @Kirsten2 ,

    There is nothing wrong with this code providing LookupEmail is a Boolean (true/false) Variable you have initiated prior determining that email exists - is this the case ?

    If(
     LookUpEmail, 
     Patch(
     DataSourceName, 
     LookUp(
     DataSourceName, 
     'Customer Email' = User().Email
     ), 
     FormControlName.Updates
     ), 
     Patch(
     DataSourceName, 
     Defaults(DataSourceName), 
     FormControlName.Updates
     )
    )

     

  • Kirsten2 Profile Picture
    383 on at

    Yes, based on my awareness it is a Boolean. It is either true or false. 

  • Kirsten2 Profile Picture
    383 on at

    Should this work too?

     

    If(
     IsBlank(
    LookUp(
     DataSourceName, 
     'Customer Email' = User().Email
     )), 
     Patch(
     DataSourceName, 
     LookUp(
     DataSourceName, 
     'Customer Email' = User().Email
     ), 
     FormControlName.Updates
     ), 
     Patch(
     DataSourceName, 
     Defaults(DataSourceName), 
     FormControlName.Updates
     )
    )
  • Verified answer
    WarrenBelz Profile Picture
    155,679 Most Valuable Professional on at

    Hi @Kirsten2 ,

    This is probably better

    With(
     {
     wID:
     LookUp(
     DataSourceName, 
     'Customer Email' = User().Email
     ).ID
     }, 
     Patch(
     DataSourceName,
     If(
     !IsBlank(wID),
     {ID: wID},
     Defaults(DataSourceName)
     ), 
     FormControlName.Updates
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Kirsten2 Profile Picture
    383 on at

    Thank you! This worked perfectly!! 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 463

#2
WarrenBelz Profile Picture

WarrenBelz 364 Most Valuable Professional

#3
11manish Profile Picture

11manish 275

Last 30 days Overall leaderboard