Skip to content

Instantly share code, notes, and snippets.

@rezanid
Created December 28, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezanid/33d22ae5381d1d159737a9645d7be098 to your computer and use it in GitHub Desktop.
Save rezanid/33d22ae5381d1d159737a9645d7be098 to your computer and use it in GitHub Desktop.
Display model-driven custom page as dialogs in Power Platform
/* This function uses Navigation API to display a centered dialog. */
/* Simple parameters are used instead of object to make the function compatible with command bar parameters. */
function displayDialog(rowId, tableName, pageName, title, contentWidth, contentHeight, primaryControl) {
const parseSize = (str, defaultStr) => (str || defaultStr || "500px").match(/([\d\.]*)(.*)/).splice(1,2);
let [w, wUnit] = parseSize(contentWidth);
let [h, hUnit] = parseSize(contentHeight);
var pageInput = {
pageType: "custom",
name: pageName,
entityName: tableName,
recordId: rowId.replace(/[{}]/g, "")
};
var navigationOptions = {
target: 2,
position: 1,
width: {value: parseFloat(w), unit: wUnit},
height: {value: parseFloat(h), unit: hUnit},
title: title
};
Xrm.Navigation.navigateTo(pageInput, navigationOptions)
.then(
function () {
if (primaryControl.getFormContext) { primaryControl.getFormContext().data.refresh(); }
else {primaryControl.data.refresh();}
}
).catch(
function (error) {
/* TODO: Add exception handling here. */
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment