cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Reinier1
New Member

Relation is lost between two records when using patch

Hi all,

 

I have a canvas app in which a record is updated in 3 successive stages. The record is stored in de MS dataverse /CDS of Power Apps.

In the first stage, the record is related to an account via the patch function. In the last stage, the record is updated and related to a "corrective action", again using patch. However, this patch sometimes removes the relation with the account. Does anyone else experience this problem? The strange thing is that I cannot reproduce the problem in a manner that it always removes the relation. 

 

Stage 1:

Patch(
'Non-conformances',
NcRecord,
{Title: InputNcTitle_1.Text},
{Part: ComboBoxPart_1.Selected},
{Quantity: Value(InputNcQuantity_1.Text)},
{'Serial/Batch Number': SerialNumberString_1.Text},
{'NC process': NcProcess1.Selected.Value},
{Account: ComboBoxSupplier_1.Selected},
{'Purchase Order': InputNcPO_1.Text},
{'Supplier Responsible': ToggleSupplierR_1.Value},
{'Shop Order': InputNcSO_1.Text},
{'NC Classification': ComboNcClass1.SelectedItems},
{Description: InputNcDescription_1.Text},
{Cause: InputNcCause_1.Text},
{Recommendation: InputNcRecommendation_1.Text},
{'NC Status':'NC Status'.Analyze}
)

 

Stage 3: 
Patch(
'Non-conformances',
NcRecord,
{'Closing Comment':InClosingComment.Text},
{'Problem Report ID':InPR.Text},
{'Corrective Action Relation':InputCaNC_1.Selected},
{'NC Status':'NC Status'.Closed}
)

3 REPLIES 3
StalinPonnusamy
Community Champion
Community Champion

Hi @Reinier1 

 

Can you validate the relation existing before the patch on Stage 3 to make sure the relation

 

If(!IsBlank(InputCaNC_1.Selected),
Patch(
'Non-conformances',
NcRecord,
{'Closing Comment':InClosingComment.Text},
{'Problem Report ID':InPR.Text},
{'Corrective Action Relation':InputCaNC_1.Selected},
{'NC Status':'NC Status'.Closed}
),

Notify("Relation not exist")

)


Thanks,
Stalin - Learn To Illuminate

Reinier1
New Member

Hi @StalinPonnusamy , 

 

The non-conformance has two relations:

  1. Account                        {Account: ComboBoxSupplier_1.Selected}, stage 1
  2. Corrective action          {'Corrective Action Relation':InputCaNC_1.Selected},  stage 3

Even if the account has a relation from stage 1, when updating at stage 3 the relation gets lost. 

I added the patch function for the account to stage 3 so it will update itself with the existing account relation if it exists. But this seems inefficient. 

 

 

 

Hi @Reinier1 

 

Option 1: Use New record. Capture the latest record in Stage 1 using Set and use in Stage 3.

Set(NewNcRecord, Patch(
'Non-conformances',
NcRecord,
{Title: InputNcTitle_1.Text},
{Part: ComboBoxPart_1.Selected},
{Quantity: Value(InputNcQuantity_1.Text)},
{'Serial/Batch Number': SerialNumberString_1.Text},
{'NC process': NcProcess1.Selected.Value},
{Account: ComboBoxSupplier_1.Selected},
{'Purchase Order': InputNcPO_1.Text},
{'Supplier Responsible': ToggleSupplierR_1.Value},
{'Shop Order': InputNcSO_1.Text},
{'NC Classification': ComboNcClass1.SelectedItems},
{Description: InputNcDescription_1.Text},
{Cause: InputNcCause_1.Text},
{Recommendation: InputNcRecommendation_1.Text},
{'NC Status':'NC Status'.Analyze}
))

 

Stage 3: 
Patch(
'Non-conformances',
NewNcRecord,
{'Closing Comment':InClosingComment.Text},
{'Problem Report ID':InPR.Text},
{'Corrective Action Relation':InputCaNC_1.Selected},
{'NC Status':'NC Status'.Closed}
)

 

Option 2: Can you try Lookup instead of referring to the record? 

 

Patch(
'Non-conformances',
LookUp('Non-conformances', Condition),
{'Closing Comment':InClosingComment.Text},
{'Problem Report ID':InPR.Text},
{'Corrective Action Relation':InputCaNC_1.Selected},
{'NC Status':'NC Status'.Closed}
)

 


Thanks,
Stalin - Learn To Illuminate

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,213)