Hello everybody,
I am having a hard time trying to figure out why I am having this problem:
I was able to narrow down to one line of code that generates the problem:
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:
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.
Thanks, Victor.
Solved! Go to Solution.
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.
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.
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.
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.
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.
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!
User | Count |
---|---|
251 | |
102 | |
94 | |
47 | |
37 |