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

I followed instructions on a blog about creating a really smart form layout. However...

Hi everyone,

 

I was struggling with autogenerated ID using excel/Onedrive as my database, until I a blog influenced me to step up to using basic Azure SQL.

 

The blog's URL for creating custom forms is here: https://baizini-it.com/blog/index.php/2017/09/28/powerapps-101-create-your-own-forms/

 

I follow each step to the T till the very last one keystone, where I set the Onselect property for the 'Save' icon with the following code:

 

Set(
    SelectedId,
    Patch(
      '[dbo].[MyTable]',
      {MyID: If(
        NewRecord,
        Blank(),
        SelectedId)},
      {Title: TextInputTitle.Text,
      MyAmount: Value(TextInputMyAmount.Text)}).MyID);
UpdateContext({Editing:false, NewRecord:false})

Everything is fine and dandy in the Powerapps studio, until I save and re-open the app.

 

 

The code falls over with numerous formulaic errors, which I believe is somehow caused by SelectedId. The error prompts for the 'Save' icon's Onselect codes upon reopening the app are as follows:ScreenHunter 362.jpg

 

ScreenHunter 363.jpg

 

 

Can anyone shed some light as to what I can do to make the code for the 'Save' Icon a bit more robust and not creating errors everytime I fire up the app?

 

Looking forward to hearing any advice about this.

LL

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: I followed instructions on a blog about creating a really smart form layout. However...

Hi @LarryLurex

Based on the formula that you provided, I don't find any syntax error with it.

Based on the error message that you provided, I think this issue is related to the value you provided for the MyID column of your SQL table.

Please take a try to modify your formula as below:

Set(
    SelectedId, 
    Patch(
      '[dbo].[MyTable]',
If(NewRecord, Defaults('[dbo].[MyTable]'), LookUp('[dbo].[MyTable]', MyID = SelectedId)) { Title: TextInputTitle.Text, MyAmount: Value(TextInputMyAmount.Text)
}
).MyID
); UpdateContext({Editing:false, NewRecord:false})

then check if the issue is solved.

In addition, please also make sure you have defined a PRIMARY KEY within your SQL table. Also please take a try to turn off/disable the the "Explicit column selection" option within Advanced settings of App Settings of your app.

More details about the Patch function in PowerApps, please check the following article:

Patch function

If the issue still exists, please consider take a try to re-create your app, and then try above formula I provided within your app, check if the issue is solved.

 

Best regards,

Kris

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.
7 REPLIES 7
Super User
Super User

Re: I followed instructions on a blog about creating a really smart form layout. However...

Hi @LarryLurex,

I'm sure that @Meneghino could give you a hand with this.

egallis
Level 10

Re: I followed instructions on a blog about creating a really smart form layout. However...

Hi @LarryLurex,

It seems to me there is a syntax problem with your code...

I would suggest to try this code:

Set(
    SelectedId, 
    Patch(
      '[dbo].[MyTable]',
      {MyID: If(NewRecord,Blank(),SelectedId)},
      {Title: TextInputTitle.Text},
      {MyAmount: Value(TextInputMyAmount.Text)}).MyID);
UpdateContext({Editing:false, NewRecord:false})

Tell us if this works for you...

Emmanuel

LarryLurex
Level: Powered On

Re: I followed instructions on a blog about creating a really smart form layout. However...

I've actually left a message at the bottom of the blog, and I'm looking forward to his feedback.

 

I thought I'd participate in this forum anyway, and it's awesome to know that @Meneghino also posts here.

 

Thanks for your reply!

LarryLurex
Level: Powered On

Re: I followed instructions on a blog about creating a really smart form layout. However...

Hi @egallis,

 

I've amended it, and the app still falls over Smiley Sad

 

Thanks for your attention!

 

Community Support Team
Community Support Team

Re: I followed instructions on a blog about creating a really smart form layout. However...

Hi @LarryLurex

Based on the formula that you provided, I don't find any syntax error with it.

Based on the error message that you provided, I think this issue is related to the value you provided for the MyID column of your SQL table.

Please take a try to modify your formula as below:

Set(
    SelectedId, 
    Patch(
      '[dbo].[MyTable]',
If(NewRecord, Defaults('[dbo].[MyTable]'), LookUp('[dbo].[MyTable]', MyID = SelectedId)) { Title: TextInputTitle.Text, MyAmount: Value(TextInputMyAmount.Text)
}
).MyID
); UpdateContext({Editing:false, NewRecord:false})

then check if the issue is solved.

In addition, please also make sure you have defined a PRIMARY KEY within your SQL table. Also please take a try to turn off/disable the the "Explicit column selection" option within Advanced settings of App Settings of your app.

More details about the Patch function in PowerApps, please check the following article:

Patch function

If the issue still exists, please consider take a try to re-create your app, and then try above formula I provided within your app, check if the issue is solved.

 

Best regards,

Kris

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

Re: I followed instructions on a blog about creating a really smart form layout. However...

Your solution worked like a charm, @v-xida-msft, wow!

 

There's a minute boo boo however; can you please amend your proposed code to include the missing coma at the end of line 5?

 

Set(
    SelectedId, 
    Patch(
      '[dbo].[MyTable]',
       If(NewRecord, Defaults('[dbo].[MyTable]'), LookUp('[dbo].[MyTable]', MyID = SelectedId)),
       {
         Title: TextInputTitle.Text,
         MyAmount: Value(TextInputMyAmount.Text)
       }
     ).MyID
);

Thanks heaps Kris, you are my guardian angel!

Community Support Team
Community Support Team

Re: I followed instructions on a blog about creating a really smart form layout. However...

Hi @LarryLurex,

Have you solved your problem?

If you have solved your problem, please go ahead and click “Accept as Solution” so that this thread will be marked for other users to easily identify.

 

Best regards,

Kris

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.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, September 18th at 8am PDT

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 288 members 2,927 guests
Please welcome our newest community members: