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

Patch function returns blank record on related table

Hi! I have a main table which is called requisition header.  I also have related tables: Requisition Form, Requisition - Attachments

I store the patch code of the 'Header' table inside a variable. Then from my Requisition form table or my 'lines' table, the value of the lookup column from the header table is the patch code.ID of the main table. 

psysn_1-1670405414803.png

As you can see, the Code column is the lookup column from the header table. There's no problem with this as the value has been passed, however, with the other columns(description, quantity, remarks, unit) it returns blank.

psysn_2-1670405521521.png

psysn_3-1670405542091.png

I have also this attachments as this is where the file goes to

 

 

psysn_0-1670405231928.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @psysn ,

Firstly please post all code in Text, particularly unformatted examples of this size. I OCR'd this so there may be spelling errors. Your problem I believe lies here

ForAll(
   colRequisitionForm,
   Patch(
      'Requisition Form',
      Defaults('Requisition Form'),
      {
         Unit: txtReqUnit.Text,
         Description: txtReqDescription.Text,
         Remarks: txtReqRemorks.Text,
         Quantity : Value(txtReqQuantity.Text),
         Code: 
         {
            Value:_ctxHeaderRequisition.AutoGeneratedID,
            Id: _ctxHeaderRequisition.ID
         }
      }
   )
);

You are patching a collection, but all the references are to control values on the screen rather than fields in the collection. You also have your ForAll backwards - it is not designed to be a Loop, although it can work this way with considerable performance penalty as it does an individual Patch for each record. ForAll() creates a Table, which can be patched in one action provided its content is correct. For new records, this is simply a Table with field names and field types matching the list. Assuming the names in the collection are the same (change if not), your Patch would be something like the above. I am not sure on the Lookup column - you should avoid these if at all possible as it depends what you have in the collection. If any of these are not in the collection and refer to controls, put the control name back and delete the aPatch.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

MVP (Business Applications)   Visit my blog Practical Power Apps

View solution in original post

2 REPLIES 2
psysn
Frequent Visitor

please help

Hi @psysn ,

Firstly please post all code in Text, particularly unformatted examples of this size. I OCR'd this so there may be spelling errors. Your problem I believe lies here

ForAll(
   colRequisitionForm,
   Patch(
      'Requisition Form',
      Defaults('Requisition Form'),
      {
         Unit: txtReqUnit.Text,
         Description: txtReqDescription.Text,
         Remarks: txtReqRemorks.Text,
         Quantity : Value(txtReqQuantity.Text),
         Code: 
         {
            Value:_ctxHeaderRequisition.AutoGeneratedID,
            Id: _ctxHeaderRequisition.ID
         }
      }
   )
);

You are patching a collection, but all the references are to control values on the screen rather than fields in the collection. You also have your ForAll backwards - it is not designed to be a Loop, although it can work this way with considerable performance penalty as it does an individual Patch for each record. ForAll() creates a Table, which can be patched in one action provided its content is correct. For new records, this is simply a Table with field names and field types matching the list. Assuming the names in the collection are the same (change if not), your Patch would be something like the above. I am not sure on the Lookup column - you should avoid these if at all possible as it depends what you have in the collection. If any of these are not in the collection and refer to controls, put the control name back and delete the aPatch.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

MVP (Business Applications)   Visit my blog Practical Power Apps

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 (2,731)