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

Variable is set to type 'error' when app is launched but when I comment out and bring back in code it works...

Hello all, to save my application, I have a global variable gblForms, when I start a new Item I set this variable to:

Set(gblForms, Defaults('Data'));

When I open a already saved item I set this variable to:

Set(gblForms,glyDraft.Selected); (glyDraft is the gallery on the app that has saved items.)

In the data entry form there are 12 screens, each screen has one form, on every screen I have a save button which has the following code:

Set(gblForms,

Patch(

'Data',

gblForms,

frmS1.Updates,

frmS2.Updates,

frmS3.Updates,

frmS4.Updates,

frmS5.Updates,

frmS6.Updates,

frmS7.Updates,

frmS8.Updates,

frmS9.Updates,

frmS10.Updates,

frmS11.Updates,

frmS12.Updates

));

The problem is that there seems to be a memory issue whereby when I start the app it seems to think this variable is not properly initialised. When I look in the variables menu I see it is set to type "error". There is a error detected in that save code above but not the two initialisers... When I comment out that save code on each screen and then I put at least one code back in it works perfectly but I have to do this every time I start the app.

I had asked a colleague to test this, there was a time where he started the app and it worked perfectly for him, making us think its my internet, and then he tried the next day and he had the same problem as me.

The problem seems to be that the compiler is not paying attention to the initialiser before interpreting the save code?

I have removed the save code from 11 of the 12 screens and left only one and it still does not work.

1 ACCEPTED SOLUTION

Accepted Solutions
C-Papa
Super User
Super User

Set(gblForms, Defaults('Data')); is a different data type to the rest of your formula

Why are you patching the data and saving all of the forms in one go? why don't you SubmitForm(frmS1) on the save button and then the same on the next screen etc etc. this will use a large amount of API request for one action. 

 

if you remove Set(gblForms, Defaults('Data')); and change the code to the below the patch should work. 

 

Patch(

'Data',

{ID:gblForms.ID},

frmS1.Updates,

frmS2.Updates,

frmS3.Updates,

frmS4.Updates,

frmS5.Updates,

frmS6.Updates,

frmS7.Updates,

frmS8.Updates,

frmS9.Updates,

frmS10.Updates,

frmS11.Updates,

frmS12.Updates

));

View solution in original post

2 REPLIES 2
C-Papa
Super User
Super User

Set(gblForms, Defaults('Data')); is a different data type to the rest of your formula

Why are you patching the data and saving all of the forms in one go? why don't you SubmitForm(frmS1) on the save button and then the same on the next screen etc etc. this will use a large amount of API request for one action. 

 

if you remove Set(gblForms, Defaults('Data')); and change the code to the below the patch should work. 

 

Patch(

'Data',

{ID:gblForms.ID},

frmS1.Updates,

frmS2.Updates,

frmS3.Updates,

frmS4.Updates,

frmS5.Updates,

frmS6.Updates,

frmS7.Updates,

frmS8.Updates,

frmS9.Updates,

frmS10.Updates,

frmS11.Updates,

frmS12.Updates

));

Fudz
Frequent Visitor

Thank you for this, so I suppose the problem was that within my dataverse table there exists a primary ID column that is iterated + 1 upon save and is a required column, hence why I need {ID:gblForms.ID}?

 

A colleague used my method but does not have a such a primary number ID so I suppose his record variable was being properly collected without any problem?

 

With your method I needed to add a conditional logic to determine whether or not an item was new, hence my code now looks like this:

If(IsNew,

Patch(

Data',

{ID:gblForms.ID},

frmS1.Updates,

frmS2.Updates,

frmS3.Updates,

frmS4.Updates,

frmS5.Updates,

frmS6.Updates,

frmS7.Updates,

frmS8.Updates,

frmS9.Updates,

frmS10.Updates,

frmS11.Updates,

frmS12.Updates

),

Patch(

Data',

gblForms,

frmS1.Updates,

frmS2.Updates,

frmS3.Updates,

frmS4.Updates,

frmS5.Updates,

frmS6.Updates,

frmS7.Updates,

frmS8.Updates,

frmS9.Updates,

frmS10.Updates,

frmS11.Updates,

frmS12.Updates

));

Set(IsNew, false)

 

My client wants all forms to be saved at one moment as they dont necessarily access the forms linearly, I suppose it would be a cause of confusion for the end user if they moved on to another screen without saving and wondering why it was not saved.

 

To solve the problem of too many API requests, I can store the save code in one verification screen that all save buttons will lead to.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,753)