
I have a model driven app that is loading a custom page using the navigateTo method as seen below:
this.openCostGrid = async (formContext) => {
const id = (formContext.data.entity.getId() || '').replace(/[{}]/g, '');
const [{ id: draftId }] = formContext.getAttribute('new_draftid').getValue() || [{}];
const draftRecord = await Xrm.WebApi.retrieveRecord('new_draft', draftId, '?$select=_new_costmodel_value');
const costModelName = draftRecord['_new_costmodel_value@OData.Community.Display.V1.FormattedValue'];
var pageInput = {
pageType: 'custom',
name: 'new_costtable_02724',
entityName: 'new_draft',
recordId: id,
};
var navigationOptions = {
target: 2,
position: 1,
width: { value: 100, unit: '%' },
title: `Cost Model: ${costModelName}`,
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions)
.then(function () {
// Called when the dialog closes
})
.catch(function (error) {
console.log(error);
});
};
Inside the custom page/canvas app editor, I have the following code running in the OnStart event:
Refresh('Drafts');
Refresh('Options');
Set(
varRecordId,
If(
IsBlank(Param("recordId")),
GUID("ad39b0f2-df2b-ee11-bdf4-00286423655c"),
GUID(Param("recordId"))
)
);
Set(
RecordItem,
LookUp(
'Options',
'Option' = varRecordId
)
);
Set(
DraftItem,
LookUp(
'Drafts',
'Draft' = GUID(RecordItem.'Draft'.'Draft')
)
);
Set(
varCostModelName,
DraftItem.'Cost Model'.Name
);
From the entity that is launching the custom page, I am retrieving a parent record of Draft and on the draft is a field for Cost Model.
The issue I am seeing is as follows:
When I open the custom page for the first time using a button on the Option form, everything works fine and the custom page displays the correct value for the cost model. If I then close the custom page modal, open a new tab, edit the draft to have a different cost model, then on the original tab, without reloading, click the button to launch the custom page, again the custom page displays the old value for the cost model. Only after refreshing the page that loads the custom page/canvas app is it retrieving the correct value.
I attempted fix this by adding the refreshes at the top of the OnStart event, but that did not fix the issue.