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 / Powerapps sql Save but...
Power Apps
Answered

Powerapps sql Save button with Lookup for data validation

(0) ShareShare
ReportReport
Posted on by 19

I have a form where a user can Create a new record that will be stored in a SQL table.

I have created a label called 'errorLabel' that displays **User Email already esixts" and the Visible parameter is set to False.

  

The sql table uses a field called UserEmail as the primary key.

 

I have added an icon button and I am trying to set the OnSelect function of this button.

When the user clicks the icon button I want to LookUp in the sql table to make sure that the new UserEmail does not exists in the SQL table.

If the record does not exists then Submit the form to the sql table for creation and then ResetForm.

If the UserEmail key value does exists in the sql table then set the Visible parameter of the 'errorLabel" to True.

 

I am having an error with my syntax... can anyone make a helpful suggestion...

 

Button Syntax - 

If(LookUp('[dbo].[Users]', UserEmail = UserEmail_DataCard.Update, UserEmail), UpdateContext({cVisible: true}) , SubmitForm(EditEmployeeForm));ResetForm(EditEmployeeForm)

 

I get two error check messages

1. invalid argument type (text) expected Boolean

2. the function'If' has some invalid argument types.

 

Any help would be appreciated.

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi,

     

    For SQL Server, in order to add records, you need an identity field set up as the primary key. For example:

     

    Field Name: userID

    Data Type: Int

    Set as an Identity column; Identity(1,1)

    Cannot receive NULL values

    Field set as a Primary Key

     

    Regarding your IF statement, the syntax for IF is "IF(logical test, true value, false value)". In your IF statement, you're bringing back the UserEmail field value, however the logical test is looking for "true" or "false". You'll need to edit that logical test part to evaluate to "true" or "false". 

     

     

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @A27152 ,

    Do you want to check if the entered UserEmail value has already been existed in your SQL Table?

     

    Based on the formula you provided, I think there is something wrong with it. The first argument of the If function is required to provide a Boolean value, but the result the LookUp(...) formula (you provided) returns a Text value.

     

    I have made a test on my side, please consider modify your formula as below:

    If(
     !IsBlank(LookUp('[dbo].[Users]', UserEmail = UserEmail_DataCard.Update)), 
     UpdateContext({cVisible: true}), 
     SubmitForm(EditEmployeeForm)
    );
    ResetForm(EditEmployeeForm)
    

    or

    If(
     !IsBlank(LookUp('[dbo].[Users]', UserEmail = UserEmailDataCardValue.Text)), 
     UpdateContext({cVisible: true}), 
     SubmitForm(EditEmployeeForm)
    );
    ResetForm(EditEmployeeForm)
    

     

    Set the OnVisible property of the Edit screen (which contains the Edit form) to following:

    UpdateContext({cVisible: false})

     

    Please consider take a try with above solution, then check if the issue is solved.

     

    Best regards,

  • A27152 Profile Picture
    19 on at

    Thanks for the information it helped me get past the road block.... Still learning the correct syntax and this was very helpful.

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 401 Most Valuable Professional

#2
11manish Profile Picture

11manish 201 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard