cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Issue with Patch post deployment

Hi All,

 

I am facing an weird issue with the Patch function. I am using an embedded canvas app on the CRM Form.

This is working fine in DEV environment but post deployment it stopped working.

 

Issue - 

1) Open the existing record ,gets the data properly,  modify data and hit save -> data is saved - works fine

2) Modify field values and save again -> data does not save and reloads the previous data

 

Below is the formula applied on 'onDataRefresh' property of ModelDrivenFormIntegration

 

Patch('DataSourceName', ModelDrivenFormIntegration.Item,
{
    'Attribute 1': If(IsBlank(DataCardValue3.Text),Blank(),Value(DataCardValue3.Text)),
     'Attribute 2': If(IsBlank(DataCardValue4.Text),Blank(),Value(DataCardValue4.Text))
}
)

 

Please suggest if i have missed anything, or what could be wrong in this case. 

 

Any help would be appreciated. Thanks in Advance

1 ACCEPTED SOLUTION

Accepted Solutions

@Poweruser1101 

 

After you SubmitForm or Patch from the button or wherever you are doing this, you should also use this formula right after:

 

 

ModelDrivenFormIntegration.RefreshForm(true);

 

 

otherwise the host Model Driven form might not refresh automatically after the changes made from inside the Canvas App and still contain the stale data.

 

See if it helps @Poweruser1101 .

 

Also for the OnDataRefresh we usually do not ever Patch over there. In most apps where we do this, we usually refresh the data source if needed (by calling Refresh(DataVerseDataTableDataSource) - reason why is the Model Driven App changes from the form, would have just changed the Dataverse data source, right? Of course this was made outside the Canvas App, so the Canvas App might not know this directly. How to make the Canvas App know this directly, would be that a simple call to Refresh(DataVerseDataTableDataSource) in the OnDataRefresh should result in reflecting those specific kinds of changes that were "technically made outside the Canvas App", inside the Canvas App by using that handy  "OnDataRefresh" property. Check if this simpler approach helps @Poweruser1101 .

 

Besides that, only in some specific cases we might perform any other checks in "OnDataRefresh" - for example in some apps, it is very important if specific Lookup columns in particular that have a relationship with another table, and/or other complex columns have values in them or are left blank and the App does something in response to one or the other - so sometimes we do this kind of re-checking there for some scenarios like that - but other than this we usually do nothing else actually. We definitely not Patch from there (unless perhaps the Patch was maybe to another data source entirely, not the Dataverse one that Model Driven App just changed, for some cases). Please clarify regarding why you have to Patch to the same data source that was just modified by the Model Driven App in case this is your requirement.

 

Keep in mind if your datasource is Dataverse, you do not need and in general should not need to Patch from OnDataRefresh to the same data source that was just sent changes via the hosting Model Diven App form - because model driven apps change that same Dataverse data source too so that may create a paradox or weird behavior. This may be related to those issues you face as well, and also, if that was the issue, it is present in the dev environment too but you may not have performed the same kinds of tests on both environments.

 

See if this helps @Poweruser1101 

View solution in original post

5 REPLIES 5
Resolver II
Resolver II

Hello @Poweruser1101 ,

 

I don't understand why you are doing the patch in the onDataRefresh property. Patch should be used in a button not in the from itself 

Could you please give us more intel about what you are trying to do?

 

Regards,

Akram

Helper I
Helper I

Hi @awerda  Thank you for responding. Since it is embedded on the crm form, requirement was to save the entered data in the embedded canvas app when the  crm Form Save button is hit, hence placed formula under 'on Data Refresh' property so this way don't need another button, and the save works too.
And the embedded app looks part of the same form

 

Below is the Form  and the embedded canvas inside it -

 

Poweruser1101_1-1608758457539.png

 

The issue is it works perfectly fine in Dev environment, but in Test Environment it behaves wierd.

Scenario -

1) Works well when the value is modified on form for the first time and hit Save

2) For Second time, it does the save twice and re-loads the previous value again

For eg : If i update a fields value from 100 to 200, it does the save twice (found this in audit history)

Update 1 : value changed from 100 to 200

Update 2 : value changed from 200 to 100

 

Not understanding why the save is happening twice which is not the case on DEV environment. If the approach is wrong do let me know, happy to be corrected.

 

Apart from patch, there's only one another formula which is applied on Total field to calculate total - 

 

IfError(

If(IsBlank('Test1 Sales Number_DataCardValue'.Text), 0, Value('Test1 Sales Number_DataCardValue'.Text)) +
If(IsBlank('Test2 Sales Number_DataCardValue'.Text), 0, Value('Test2 Sales Number_DataCardValue'.Text)) +
If(IsBlank('Test3 Sales Number_DataCardValue'.Text), 0, Value('Test3 Sales Number_DataCardValue'.Text)) +
If(IsBlank('Test4 Sales Number_DataCardValue'.Text), 0, Value('Test4 Sales Number_DataCardValue'.Text))

, ThisItem.'Stored Value of the field').

@Poweruser1101 

 

After you SubmitForm or Patch from the button or wherever you are doing this, you should also use this formula right after:

 

 

ModelDrivenFormIntegration.RefreshForm(true);

 

 

otherwise the host Model Driven form might not refresh automatically after the changes made from inside the Canvas App and still contain the stale data.

 

See if it helps @Poweruser1101 .

 

Also for the OnDataRefresh we usually do not ever Patch over there. In most apps where we do this, we usually refresh the data source if needed (by calling Refresh(DataVerseDataTableDataSource) - reason why is the Model Driven App changes from the form, would have just changed the Dataverse data source, right? Of course this was made outside the Canvas App, so the Canvas App might not know this directly. How to make the Canvas App know this directly, would be that a simple call to Refresh(DataVerseDataTableDataSource) in the OnDataRefresh should result in reflecting those specific kinds of changes that were "technically made outside the Canvas App", inside the Canvas App by using that handy  "OnDataRefresh" property. Check if this simpler approach helps @Poweruser1101 .

 

Besides that, only in some specific cases we might perform any other checks in "OnDataRefresh" - for example in some apps, it is very important if specific Lookup columns in particular that have a relationship with another table, and/or other complex columns have values in them or are left blank and the App does something in response to one or the other - so sometimes we do this kind of re-checking there for some scenarios like that - but other than this we usually do nothing else actually. We definitely not Patch from there (unless perhaps the Patch was maybe to another data source entirely, not the Dataverse one that Model Driven App just changed, for some cases). Please clarify regarding why you have to Patch to the same data source that was just modified by the Model Driven App in case this is your requirement.

 

Keep in mind if your datasource is Dataverse, you do not need and in general should not need to Patch from OnDataRefresh to the same data source that was just sent changes via the hosting Model Diven App form - because model driven apps change that same Dataverse data source too so that may create a paradox or weird behavior. This may be related to those issues you face as well, and also, if that was the issue, it is present in the dev environment too but you may not have performed the same kinds of tests on both environments.

 

See if this helps @Poweruser1101 

View solution in original post


@Poweruser1101 wrote:

The issue is it works perfectly fine in Dev environment, but in Test Environment it behaves wierd.

 


About this one, in the production environment go to make.powerapps.com, make sure on upper right the correct environment is selected, and then from the left side go to Data -> Connections. Go ahead and delete all of them that the Canvas App is using. Especially pay attention in case there are duplicates and delete all of them.  Even if there is no duplicate, just delete all of them that the Canvas App is using.

 

What this does is it will reprompt for the permissions. If you are feeling nervous about it, just open the Canvas App in Play mode or Edit mode right after doing this, and it should just simply reprompt for the permissions - this should re-establish the Connections.

 

Check if this helps as well @Poweruser1101 

Helper I
Helper I

@poweractivate Apologies was on leave so did not have access to this account. Would really like to thank you for providing a detailed explanation on this. The data on the form is only getting modified via the canvas app and no change is happening through Model Driven Form hence ideally this should work. Since this was working in DEV environment and failing in TEST, I was not understanding why did it work in DEV though then. 

This issue has been raised to microsoft now to look into and I would come back and update here whatever is the reason behind it.

 

As per you suggestion, I did create a button on the canvas app in the TEST environment and moved the patch formula from ondatarefresh property to onselect property of the button and it worked!!Thank you for suggesting this.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (46,655)