Hi,
I am having troubles using the refresh() function properly.
Following scenario:
I am developing an Order Confirmation Dialog as a "Custom Page".
In the Custom Page, Users can confirm the Order which should close the Custom Page and refresh the Dynamics Form.
Additionally, once the Order is confirmed, all fields should be Read-Only.
- Custom Page: Patches Order Statuscode and Back() to return to Dynamics -> works fine
- JavaScript registered "On Load" on the Order Form which disables all Controls -> works fine when using the UI "Refresh" Button or when F5 or when navigating to a record
- In the Callback of the Custom Page I try to refresh the Form to show the new updated Status code -> doesnt work
Find my JS Code below. The debugger in the refresh Callback (line 31) does not get triggered. Additionally I shouldn't even need the manual call to the disableAllFields method as the refresh Method should fire the event already as can be seen in the documentation (https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/events/form-data-onload)

function openConfirmPage(primaryControl, id)
{
debugger;
var recordId = id.replace("{", "").replace("}", "");
console.log("Id: " recordId);
var pageInput = {
pageType: "custom",
name: "prefix_salesorderconfirmation_581cd",
entityIdField: "salesorder",
recordId: recordId
};
var navigationOptions = {
target: 2,
position: 2,
width: {
value: 80, unit: "%"
},
title: "Confirm Sales Order"
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions)
.then(
function ()
{
debugger;
primaryControl.data.refresh().then(
function () {
debugger;
disableAllFields(primaryControl);
}
);
}).catch (
function (error)
{
console.log(error);
});
}
function disableAllFieldsHelper(executionContext) {
debugger;
var formContext = executionContext.getFormContext();
disableAllFields(formContext);
}
function disableAllFields(formContext) {
debugger;
var status = formContext.getAttribute("statecode").getValue();
var statusReason = formContext.getAttribute("statuscode").getValue();
if(statusReason == 1 || status != 0) return;
formContext.ui.controls.forEach(function (control, i) {
if (control && control.getDisabled && !control.getDisabled()) {
control.setDisabled(true);
}
});
}