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

Notifications

Announcements

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard