web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Launch Custom Page - M...
Power Apps
Answered

Launch Custom Page - Model Driven App

(0) ShareShare
ReportReport
Posted on by 14

In a model driven app form, I am looking to have a button in a section of the form that allows for a dialog popup to show a custom page.

 

Dmschellaz_0-1701400208194.png

 

Here is my HTML Code:

<!DOCTYPE html>
<html>
<head>
 <title>Custom Dialog Launcher</title>
 <style>
 .custom-button {
 background-color: blue;
 color: white;
 border: none;
 padding: 10px 20px;
 border-radius: 15px;
 cursor: pointer;
 font-size: 16px;
 }
 </style>
</head>
<body>
 <button class="custom-button" onclick="openCustomDialog();">Launch Custom Page</button>

</body>
</html>

 

 

Here is the javascript code that I have as a web resource that is in an On-Load event for the form:

function openCustomDialog() {
 var pageInput = {
 pageType: "custom",
 name: "your_custom_page_logical_name" // Replace with the logical name of your custom page
 };
 var navigationOptions = {
 target: 2, // Open as a dialog
 width: { value: 50, unit: "%" },
 height: { value: 80, unit: "%" },
 title: "Your Dialog Title" // Replace with the title for your dialog
 };

 if (Xrm.Page && Xrm.Page.navigation) {
 Xrm.Page.navigation.navigateTo(pageInput, navigationOptions).then(
 function () {
 // Called when the dialog has been opened successfully
 },
 function (error) {
 // Handle error
 console.error("Error opening custom dialog:", error);
 }
 );
 } else {
 console.error("Xrm.Page is not available.");
 }
}

 

When clicking on the button - I get a console log of: 

Dmschellaz_1-1701400342679.png

 

Any thoughts?

Categories:
I have the same question (0)
  • narayan225 Profile Picture
    2,547 Super User 2025 Season 2 on at

    @Dmschellaz 

     

    I am not sure what you are doing by checking Xrm.Page and Xrm.Page.Navigation. Xrm.Page is deprecated and not supported anymore. Simply use Xrm.Navigation.

     

    Please check the following documentation: https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/navigate-to-custom-page-examples

     

    Hope this helps.

    Cheers!

  • Verified answer
    v-xiaochen-msft Profile Picture
    on at

    Hi @Dmschellaz ,

     

    Please try this

    html

    <!DOCTYPE html>
    <html>
    
    <head>
     <title>Custom Dialog Launcher</title>
     <style>
     .custom-button {
     background-color: blue;
     color: white;
     border: none;
     padding: 10px 20px;
     border-radius: 15px;
     cursor: pointer;
     font-size: 16px;
     }
     </style>
    </head>
    
    <body>
     <button class="custom-button" onclick="openCustomDialog();">Launch Custom Page</button>
     <script>
     // This script should be in the HTML web resource.
     // No usage of Xrm or formContext should happen until this method is called.
     function setClientApiContext(xrm, formContext, openCustomDialog) {
     // Optionally set Xrm and formContext as global variables on the page.
     window.Xrm = xrm;
     window._formContext = formContext;
     window.openCustomDialog = openCustomDialog;
     // Add script logic here that uses xrm or the formContext.
     }
    
    
     </script>
    </body>
    
    </html>

     

    Js

    function test2(executionContext) {
     var formContext = executionContext.getFormContext();
     var wrControl = formContext.getControl("WebResource_new_1");
     if (wrControl) {
     wrControl.getContentWindow().then(
     function (contentWindow) {
     contentWindow.setClientApiContext(Xrm, formContext, openCustomDialog);
     }
     )
     }
    }
    
    var openCustomDialog = function () {
     var pageInput = {
     pageType: "custom",
     name: "new_testpagefortable8_28932" // Replace with the logical name of your custom page
     };
     var navigationOptions = {
     target: 2, // Open as a dialog
     width: { value: 50, unit: "%" },
     height: { value: 80, unit: "%" },
     title: "Your Dialog Title" // Replace with the title for your dialog
     };
    
     Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
     function () {
     // Called when the dialog has been opened successfully
     },
     function (error) {
     // Handle error
     console.error("Error opening custom dialog:", error);
     }
     );
    

     

    vxiaochenmsft_0-1701414450969.png

     

    Best Regards,

    Wearsky

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard