cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
A27152
Level: Powered On

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
Community Support Team
Community Support Team

Re: Powerapps sql Save button with Lookup for data validation

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
Level: Powered On

Re: Powerapps sql Save button with Lookup for data validation

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

 

 

Community Support Team
Community Support Team

Re: Powerapps sql Save button with Lookup for data validation

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

A27152
Level: Powered On

Re: Powerapps sql Save button with Lookup for data validation

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
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,570)