Created
December 28, 2021 13:55
-
-
Save rezanid/33d22ae5381d1d159737a9645d7be098 to your computer and use it in GitHub Desktop.
Display model-driven custom page as dialogs in Power Platform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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