cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vllanso
Advocate II
Advocate II

App had 0 errors when last saved, but shows many errors after reopening with only one difference in a record Patch

Hello everybody,

 

I am having a hard time trying to figure out why I am having this problem:

  • I have an app that, before it is saved from the development/studio environment, it shows 0 errors
  • But if I exit the development page and reopen the app for editing, now it shows many errors related with a record

 

I was able to narrow down to one line of code that generates the problem:

  • If that line of code IS NOT present in the code, then if I save and exit, and then  reopen the app, it shows 0 errors
  • If that line of code IS present in the code, when I save it, it shows 0 errors, but when I exit and reopen to edit it, it shows many errors

 

Thay are all related with a record (regItemObr) that I use to read from a table (tblOfertasObras) and also in a form.

 

In different parts of the program I have the following sentences related with the record:

UpdateContext( { regItemObr: LookUp( TblOfertasObras, IDObra = frmCMOfeObra.LastSubmit.IDObra ) } );
UpdateContext( { regItemObr: Patch( TblOfertasObras, regItemObr, { FechaEscritura: Now(), ActualizadoPor: TXT_USER_EMAIL } ) } );
UpdateContext( { regItemObr: Blank() } );
UpdateContext( { regItemObr: LookUp( TblOfertasObras, IDOferta = varOfertaID ) } );
UpdateContext( { regItemObr: Patch( TblOfertasObras, Defaults(TblOfertasObras), { IDOferta: varOfertaID, CreadoPor: TXT_USER_EMAIL } ) } );

 

And then I have the "offending" line of code:

UpdateContext( { regItemObr: Patch( regItemObr, { ObraNombre: "" } ) } );

 

As mentioned before:

  • when I save the app, it shows 0 errors
  • but if I exist and reopen the app for editing, I get many errors
  • and the referenced table field (ObraNombre) is indeed a valid field in the record and table

 

And the error related with the "offending" line is "Invalid argument type (Error). Expecting table instead", but many other lines show an error (see some sample below).

 

Can you think of any reason why that simple line can generate such error.

 

vllanso_0-1661968347086.png

vllanso_1-1661968862952.png

 

 

Thanks, Victor.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@vllanso 

Yes, that might be the "part" of the formula that is a problem, but it depends on the entirety of the formula that it is in.

From your image of the error, it appears that there is much more to the formula than just that line.  And, it would make a difference as to where in the formula the function exists.  

In other words, as PowerApps tries to infer the schema, the order of operations that determine that schema are paramount.  

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@vllanso 

Yes!  What is the entire formula that the error is in?

 

PowerApps constantly has to infer the schema of any records in your app.  It can get confused quickly when you try to manipulate the columns of the record like you are.  More importantly is the order of operations of those functions.  When the app is first opened, it has to look through the entire app formulas and try to determine what the schema of the record will be.  If it sees functions that change only one column, it can start to infer that it only has that column.  It's kind of hard to type out exactly what that process is, but suffice to say, this can happen quickly and turn things bad.  Many times this happens when you are building your formulas and then, once the editor has inferred the schema incorrectly, it "sticks" until you close and re-open the app.  However, this also happens the other way, which is to say that as you alter your app, it "builds" the schema it thinks it should be based on your changes and then all works fine when you are editing.  Then you close the app and re-open and it doesn't work - why?  Because there was some edit that you made previously that it "used" in its inference and now it doesn't exist - so when it attempts to re-evaluate the schema, it cannot.

 

Hopefully this makes some sense and is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
vllanso
Advocate II
Advocate II

Hello @RandyHayes !

 

thanks for your quick response. 

Now I can understand why it is happening ... but unfortunately I am not sure how to solve it.

 

Is there a way to "help" powerapps to infer the correct schema ? 

As mentioned, the "offending" formula is just:

UpdateContext( { regItemObr: Patch( regItemObr, { ObraNombre: "" } ) } );

 

thanks again, Victor.

RandyHayes
Super User
Super User

@vllanso 

Yes, that might be the "part" of the formula that is a problem, but it depends on the entirety of the formula that it is in.

From your image of the error, it appears that there is much more to the formula than just that line.  And, it would make a difference as to where in the formula the function exists.  

In other words, as PowerApps tries to infer the schema, the order of operations that determine that schema are paramount.  

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
vllanso
Advocate II
Advocate II

Thanks again @RandyHayes .

 

I started "playing around" with your idea of the importance of the order of the formulas to help PowerApps to determine the schema and found out that, if I include the following formula in very begining of the OnVisible method of the screen, then after saving and reopening the app, the errors went away.

If( 1 > 2,
UpdateContext( { regItemObr: LookUp( TblOfertasObras, IDObra = -1 ) } );
);

 

So many thanks for your ideas !!

 

Regards, Victor.

RandyHayes
Super User
Super User

@vllanso 

Yes, just be cautious with the manipulation of the schemas and how the app needs to infer its columns.  Best to keep things as simple as possible so that the formula editor can infer without confusion.  Those things sometimes creep up later on, like at play time.  

Glad it helped!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,175)