cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
westerdaled
Post Patron
Post Patron

Is it ilegal to update a global record with a local record value ?

Hi

 

I went to bed yesterday reassured that I tested the following Power App to ensure it all works. Indeed, there are items in the gallery to prove it worked.

  • In a gallery  > icon I set gblSelectedRecord to Parent.Selected, then naviate to my edit form
  • In my editform I set Item to gblSelectedRecord
  • In the form submit button, I take a local copy of the form data 


 

 

 

UpdateContext({lclCurrentFormRecord : Commun_EditForm.Updates});

 

 

 

  • Now in my Submit button, if I am in FormMode,New and I may let the user update an existing  record that matches the id fields ,  with one ore more form values, just entered by the user.

 

 

 

Set(gblSelectedRecord, Patch(gblSelectedRecord,{Rec_Id: gblSelectedRecord.Rec_Id},  {Comment:lclCurrentFormRecord.Comment},{Update_Date_TM: Text(Now())} ));

 

 

 

 

This morning,  is a different story : the Power App is freaky out about using a local (context) record field to replace global record field  - it removed the code where I set global var to  Parent.Selected in the gallery. 

 

So in this unique requirement,  do I use global vars both outside and inside the screen to avoid upsetting the Power App!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@westerdaled 

Yes, I encounter this quite often.  Most of my apps have a small amount of variables and there is usually one that "carries" a current record I am working on.

I find that in places where I want to impact the variable in some way, say alter a column value, ex.

   Set(glbCurrentRecord, Patch(glbCurrentRecord, {aColumn:"something"}))

That many times while typing in that formula, all of a sudden the whole app now has hundreds of errors.  What is happening is that the formula editor is re-evaluating the schema and if I haven't completely typed out the name of a column (or I misspelled it accidentally), then it breaks the schema in the "mind" of the editor. Then the annoying, save, exit, reload.

I have learned that when I put these in, I usually will rename the variable (ex. glbCurrentRecord1) until I finish typing in the rest of the formula.  Then if it is all without mistake, I change the variable name back.  It helps some.

 

Thanks for the encouragement on the videos...I have a long backlog of videos to finish and need to carve out some time to publish more.  I am so glad you learned a lot from the forms video...it definitely was a long one!

_____________________________________________________________________________________
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

8 REPLIES 8
RandyHayes
Super User
Super User

 

@westerdaled 

Yes, you can do this, but be very cautious about the schema of the variables.  If your schema from the local to the global does not match in any way, then PowerApps will not like it.

Also, assigning record type variables is perfectly fine, but be aware that the PowerApps designer has to infer the signature from all of the places you set the variables.  This can go wacky sometimes.  Once the PowerApps designer has inferred an incorrect schema, the only way to force it to reevaluate the schema is to exit the designer and come back in.  It's one of those things where you can make a slight change in an assignment of a variable in a formula and all of a sudden your app with 0 errors can now have hundreds of errors, and they are all related to that variable.  There is nothing you can do to correct it except to exit and come back in.

 

I hope this 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!
westerdaled
Post Patron
Post Patron

@RandyHayes 

 

Thanks for the advice. In this instance I have made all record vars global but as you say this maybe a schema issue , and so may still haunt me. I will keep keep calm and carry on testing.

 

Btw Pls keep posting your videos on YouTube , I really got to master forms, thanks to your 2.5 hour epic !

RandyHayes
Super User
Super User

@westerdaled 

Yes, I encounter this quite often.  Most of my apps have a small amount of variables and there is usually one that "carries" a current record I am working on.

I find that in places where I want to impact the variable in some way, say alter a column value, ex.

   Set(glbCurrentRecord, Patch(glbCurrentRecord, {aColumn:"something"}))

That many times while typing in that formula, all of a sudden the whole app now has hundreds of errors.  What is happening is that the formula editor is re-evaluating the schema and if I haven't completely typed out the name of a column (or I misspelled it accidentally), then it breaks the schema in the "mind" of the editor. Then the annoying, save, exit, reload.

I have learned that when I put these in, I usually will rename the variable (ex. glbCurrentRecord1) until I finish typing in the rest of the formula.  Then if it is all without mistake, I change the variable name back.  It helps some.

 

Thanks for the encouragement on the videos...I have a long backlog of videos to finish and need to carve out some time to publish more.  I am so glad you learned a lot from the forms video...it definitely was a long one!

_____________________________________________________________________________________
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!
westerdaled
Post Patron
Post Patron

@RandyHayes 

 

Turns out I wasn't quite there.  Loaded up the Power App and this morning and the Edit form that is open by selected an item in the gallery is now broken.

 

this 'bug' may have been the source of my woes and not say using local vars to update the global selected record , the patch statement.

 

Gallery Parent dot Selected not working.PNG

RandyHayes
Super User
Super User

@westerdaled 

In that particular formula you are trying to set the global variable to the Selected item of your Gallery.  If you are using that variable then in other places that rely on the signature/schema of that record to be based on the DataSource (ex. an EditForm), then you need to make sure it is identical.

The first place I look at would be the Items property of the gallery.  If you are manipulating the schema of the Items in the Gallery (i.e. adding, removing or showing only certain columns, or grouping) then you will have a schema mismatch. 

_____________________________________________________________________________________
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!
westerdaled
Post Patron
Post Patron

@RandyHayes 

Thanks for reaching out.  I was going to post an update, as the form is now broken again 😥.  Of course this worked yesterday.   I think the issue is I am sucessfully selecting the gallery item and going to the editform with the item ( set to a glb var). Then if I attempt to change the glb var by replacing it with a lookup of an existing record , then I see those lovely red indicators 

 

Note global var is unique to this form and the gallery above.  I have also removed the lcl vars that participate in the form submit or patch, so the error is strange. 

 

Commun Gallery issue.png

 

I am having to finish for the day but will look at this issue over the weekend to see if I can post up any diagnostic details. 

RandyHayes
Super User
Super User

@westerdaled 

Sounds good...look it over and see.  Definitely look at the Items property of the Gallery and also, you mention you set this to a LookUp...what is that looking like?  Somewhere there is a schema mismatch that is causing the app to "weird out".

_____________________________________________________________________________________
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!

@RandyHayes 

 

I think I have located the issue:

// Here I made the mistake of replacing the whole form record with the the global var
// populated by a LookUp
//Set(gblSelectedRecord, gblExistingRecord);
// replace any record columns incl the discuss text, before  we display on the form

// so by removing the above line I can make the changes required hjere
Set(gblCommunSelectedRecord, Patch(gblExistingRecord,{Rec_Id: gblExistingRecord.Rec_Id}, {Discuss:gblCurrentFormRecord.Discuss}, {Update_Date: Text(Now())} ));

 

 

 

 

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 (3,733)