You're absolutely right to explore this—passing data back from a custom page dialog in a model-driven app using Xrm.Navigation.navigateTo()
is a common challenge, and unfortunately, Power Fx's Back()
function does not support returning values directly to the calling JavaScript context.
However, there is a workaround that developers have successfully used, and it avoids the need for a custom PCF. Here's a summary of the approach:
You can pass structured data into the custom page by serializing it into the recordId
field:
const pageInput = {
pageType: "custom",
name: "your_custom_page_name",
entityName: "your_entity_logical_name",
recordId: JSON.stringify({
recordId: "someId",
sessionId: "uniqueSessionId",
additionalParams: { foo: "bar", userId: "12345" }
})
};
Xrm.Navigation.navigateTo(pageInput, { target: 2, position: 1, width: { value: 50, unit: "%" } });
In the custom page, use Power Fx to parse the incoming data:
Set(varInput, ParseJSON(Param("recordId")));
Set(gblSessionId, Text(varInput.sessionId));
Set(gblAdditionalParams, ParseJSON(varInput.additionalParams));
Since Back()
can't return values, you can simulate a callback using a custom Dataverse table (e.g., custompagescallback
) and a session ID:
Write the result to the custom table from Power Fx when the user clicks "Submit":
Patch(custompagescallback, Defaults(custompagescallback), {
sessionId: gblSessionId,
resultData: JSON(gblResult)
});
Back();
In JavaScript, after the dialog closes, poll or fetch the result using the session ID:
Xrm.Navigation.navigateTo(pageInput, navOptions)
.then(() => fetchCallbackData(sessionId))
.then((cbData) => {
if (cbData) {
// Use the returned data
console.log("Callback data:", cbData);
}
});
WarrenBelz
770
Most Valuable Professional
stampcoin
494
MS.Ragavendar
399