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

Form does not submit to SQL Server DB

Hey,

 

I have the following issue:

I created a form in PowerApps. When trying to submit data, it says that the field "ProductID" is required - though I added it.

 

powerapps_error_1.JPG

 

I'm suspicious that it is because I use a drop-down here and somehow I added the items wrongly. Although - based on the DB it should work well:

 

powerapps_error_2.JPG

 

I'm applying exactly the same method for the "Country" field (see 1. image, top left corner of the form) and there it works.

 

Is it a bug maybe? Or am I missing some necessary setting here?

 

Thanks,

Tamás

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Level 10

Re: Form does not submit to SQL Server DB

Hi @Gellai_Tamas, absolutely no problem, we will get it working.

I just noticed that you have date columns, these are currently problematic in PowerApps.

Here is a copy of another post of mine...

 

There SQL Server / Azure SQL DB connector currently has some bugs, including the following:
1) After a field contains a value, you cannot set the value back to null from PowerApps
2) There are intermittent issues writing numbers with more than 7 significant figures to the database
3) Date type columns cannot be filtered using > or < operators
4) Writing to date type columns is problematic
 
As a work-around for 3) and 4) I now store all date information as an integer of value yyyymmdd.  This allows me to filter using > and < operators as well as avoid all pitfalls with time zones.
 
I know that the PowerApps team is working to resolve all the above, and there should be a new connector out in July sometime.
 
Hope this helps.
 
PS I have many posts on all the above and more if you want to search the community

PPS Since this is a problem with the connector, I imagine it is the same whether you use a standard form or the individual controls

21 REPLIES 21
Ancherl
Level: Powered On

Re: Form does not submit to SQL Server DB

Hi,@Tamás

According to your statement, I want to know which form do you submit? In other words, which data source is the form which you created  connected to?

 

Regards,

Ancherl

Gellai_Tamas
Level: Powered On

Re: Form does not submit to SQL Server DB

Hi @Ancherl,

 

I'm connected to an SQL Server database. The DB sits on a company VM, I connect to it through an on-premise data gateway. Weird thing is that when I exclude Country and Product, the form works (but obviously without these 2 most important data points a form submission is totally useless).

 

The problem could be that both Country and Product should be chosen by the form user through a drop-down list and these 2 are sitting in different tables within the DB:

  • '[dbo].[Country] contains a CountryID and a CountryName column
  • '[dbo].[Product] contains a ProductID and a ProductName column

while entered data feeds into another table.

 

What do you think?

 

Thanks,

Tamás

Gellai_Tamas
Level: Powered On

Re: Form does not submit to SQL Server DB

Hi @Ancherl and everyone seeing this,

 

At least I managed by now that the form submits without errors but the fields that are set to drop down list are not submitted into the SQL Server DB.

 

These are my current settings:

Capture1.JPGThe form's data loads into a table called '[dbo].[Usage]'. The drop down uses another table as datasource: '[dbo].[Country]' where there are 2 columns: CountryID and CountryName.

 

These are the drop down item settings:

Capture2.JPG

 

 I choose the country from the drop down list and the form data goes into the DB - except the Country value.

Capture3.JPG

 

 

 

I'm stuck here and haven't yet found any solution here in the forum...

 

Any ideas?

 

Cheers,

Tamás

 

 

 

Meneghino
Level 10

Re: Form does not submit to SQL Server DB

Hi @Gellai_Tamas

I suspect that the form submit operation is maybe trying to post the text instead of the id to the column, or not at all.

In order to avoid any customisation issues with forms, I generally create my own from the controls.  I work mostly with Azure SQL DB, which is the same as SQL Server DB for PowerApps.

You can then use a Patch statement in the submit button, so that it submits the ID chosen in the dropdown instead of the text.

An example code for the submit button follows for the form below. Please note the use of ID for entity and vendor

UpdateContext({Saving: true});

Patch('[dbo].[Invoices]', If(New || Copying, Defaults('[dbo].[Invoices]'), GalleryInvoices.Selected),

	{
	Invoice_date_int: Value(Text(DateValue(TextInputInvoiceDate.Text), "[$-en-GB]yyyymmdd")),
	Invoice_title: TextInputInvoiceTitle.Text,
	Invoiced_entity: DropdownEntityInvoiced.Selected.ID,
	Vendor: DropdownVendor.Selected.ID,
	Invoice_currency: DropdownInvoiceCurrency.Selected.Currency_code,
	Invoice_amount: Value(TextInputInvoiceAmount.Text),
	File_name: TextInputInvoiceFilename.Text
	}
);
UpdateContext({Editing: false, New:false, Copying:false, Saving: false})

__.JPG

 

 

Gellai_Tamas
Level: Powered On

Re: Form does not submit to SQL Server DB

Hi @Meneghino,

 

Thanks a lot for your quick feedback, I'm 99% you're right. I suspected this is something around the different types (text vs number) and that Patch should be the solution.

I'm not quite sure about my code though:

 

Submit button's OnSelect syntax is now:

 

UpdateContext({Saving: true});

Patch('[dbo].[Usage]', If(New || Copying, Defaults('[dbo].[Usage]'), CountryName.Selected),

	{
	CountryID: DropDownCountryName.Selected.ID,
	}
);
UpdateContext({Editing: false, New:false, Copying:false, Saving: false})

where

 

  • '[dbo].[Usage]' is the data source where I want to submit the data to.
  • CountryID and CountryName are columns in the table '[dbo].[Country]' where I get the items from for the drop down list

I admit I've just started to learn PowerApps and the functions and syntaxes and shouldn't have undertaken developing any business apps that my boss wants - but what can I do now?... Smiley Happy

 

Could you please suggest what code to use? Maybe I'm missing the SubmitForm() function here?

 

Thanks,

Tamás

Highlighted
Meneghino
Level 10

Re: Form does not submit to SQL Server DB

Hi @Gellai_Tamas

Apologies for confusing you, the New and Copying are just some context variables that I use to keep track of whether I am editing an existing record or creating a new one. They are not required.

Let's make it even simpler.  If you want to create a new record, then all you need for is a button with the following OnSelect property.  This is not linked to a standard form, you do not need standard forms.

Please note that the operation will work only if there are no other required fields in your table.

Patch('[dbo].[Usage]', Defaults('[dbo].[Usage]'),
	{
	CountryID: DropDownCountryName.Selected.ID
	}
)

If there are other required fields, say MyNumericField and MyTextField, then you need to add text input controls to the app and do something like this:

Patch('[dbo].[Usage]', Defaults('[dbo].[Usage]'),
	{
	CountryID: DropDownCountryName.Selected.ID,
	MyNumericField: Value(TextInput1.Text),
	MyTextField: TextInput2.Text
	}
)

Please let me know how you get on.

Gellai_Tamas
Level: Powered On

Re: Form does not submit to SQL Server DB

Hi @Meneghino,

 

Unfortunately neither solution works - I get an error saying "expected value ParenClose, found value Error".

Besides, shouldn't I use the SubmitForm() function for the button's OnSelect property? Because now the button is inactive with the Patch function there only.

 

Cheers,

Tamás

Meneghino
Level 10

Re: Form does not submit to SQL Server DB

Hi @Gellai_Tamas

are you sure you also copied the closing parenthesis at the bottom of the code?

As mentioned in my posts, you do not need a standard form.  SubmitForm() is for submitting a form, if you have one.

You can just create the single controls (i.e. dropdowns, textinputs etc.) and then use the Patch function to write the new record ot the changes to the database.

Hope this helps.

Gellai_Tamas
Level: Powered On

Re: Form does not submit to SQL Server DB

Hi @Meneghino,

 

Yep, syntax is right.

I've tried to follow your method: adding single controls instead of a standard form. This is the situation right now:

 

1. My database:

 

 PA_db.JPG

 

 2. The form:

 

 PA_form.JPG

 

 3. An example for the way I add items to the dropdown from another table:

 

 PA_items.JPG

 

4. The code I use for the Submit button:

 

Patch('[dbo].[Usage]', Defaults('[dbo].[Usage]'),
	{
	CountryID: DropdownCountry.Selected.ID,
    ProductID: DropdownProduct.Selected.ID,
    UserID: DropdownUser.Selected.ID,
    UsageDate: Value(Text(DateValue(DatePickerUsageDate.Text))),
    PlannedUsage: Value(PlannedUsageInput.Text),
    ActualUsage: Value(ActualUsageInput.Text),
	}
)

And still I get the "expected value ParenClose, found value Error" message.

 

 

Might I have missed a step/setting?

 

Thanks,

Tamás