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

Powerapps sql Save button with Lookup for data validation

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.

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
DougPearce
Frequent Visitor

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

 

 

v-xida-msft
Community Support
Community Support

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,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

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

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,163)