How to Open Popup from Ribbon Button in Dynamics 365 CRM

How to Open Popup from Ribbon Button in Dynamics 365

How to Open Popup from Ribbon Button in Dynamics 365

Ribbon buttons in Dynamics 365 provide a powerful way to extend system functionality and improve user experience. One common requirement is opening a popup window when a user clicks a custom ribbon button.

Using JavaScript and the Xrm.Navigation API, you can easily open dialogs, custom pages, web resources, or forms from a ribbon button.

In this article, we'll learn how to create a custom ribbon button and open a popup in Dynamics 365.


Why Use Ribbon Button Popups?

Popup dialogs help users:


Prerequisites

Before starting, ensure you have:


Business Scenario

Suppose users need to enter comments before closing a Case record.

Requirement

When the user clicks:

Close Case

A popup dialog should appear and collect user input before proceeding.


Step 1: Create a JavaScript Web Resource

Create a new JavaScript Web Resource.

Example:

new_OpenPopup.js

Add the following function:

function openPopup(primaryControl) {

    var pageInput = {
        pageType: "webresource",
        webresourceName: "new_PopupPage"
    };

    var navigationOptions = {
        target: 2,
        width: 600,
        height: 400,
        position: 1
    };

    Xrm.Navigation.navigateTo(
        pageInput,
        navigationOptions
    ).then(
        function () {
            console.log("Popup closed");
        },
        function (error) {
            console.log(error.message);
        }
    );
}

Save and publish the web resource.


Step 2: Create a Web Resource Popup Page

Create an HTML Web Resource.

Example:

new_PopupPage.html

Sample HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Popup Dialog</title>
</head>
<body>

<h2>Dynamics 365 Popup</h2>

<p>Enter your comments below:</p>

<textarea rows="5" cols="50"></textarea>

<br><br>

<button onclick="window.close();">
Close
</button>

</body>
</html>

Save and publish.


Step 3: Create Ribbon Button

Using Ribbon Workbench:

Configure Button

Property Value
Label Open Popup
Command OpenPopupCommand
Icon Custom Icon

Step 4: Create Command

Create a new command:

OpenPopupCommand

Add a JavaScript Action:

Publish the changes.


Step 5: Test the Popup

Steps

  1. Open a Dynamics 365 record.
  2. Click the custom ribbon button.
  3. Popup window opens.
  4. Enter information.
  5. Close popup.

Result

The popup displays successfully from the ribbon button.


Open a Custom Page in Popup

Power Apps Custom Pages can also be opened.

function openCustomPage() {

    var pageInput = {
        pageType: "custom",
        name: "new_CustomPage"
    };

    var navigationOptions = {
        target: 2,
        width: 800,
        height: 600,
        position: 1
    };

    Xrm.Navigation.navigateTo(
        pageInput,
        navigationOptions
    );
}

Result

Custom Page opens inside a modal dialog.


Open Entity Form in Popup

function openAccountForm() {

    var pageInput = {
        pageType: "entityrecord",
        entityName: "account"
    };

    var navigationOptions = {
        target: 2,
        width: 700,
        height: 500,
        position: 1
    };

    Xrm.Navigation.navigateTo(
        pageInput,
        navigationOptions
    );
}

Result

Account form opens as a popup dialog.


Real-Time Business Scenario

Requirement

Sales users need a quick form to create follow-up activities.

Solution

Result

Users can create activities without leaving the current record, improving efficiency and productivity.


Common Errors

1. Function Not Found

Cause:

Incorrect JavaScript function name.

Solution:

Verify that openPopup matches the Ribbon Command configuration.

2. Web Resource Not Found

Cause:

Incorrect web resource name.

Solution:

Verify that new_PopupPage exists and is published.

3. Popup Not Opening

Cause:

JavaScript error.

Solution:

Open Browser Developer Tools → Press F12 → Check the Console tab for errors.

Best Practices


Advantages of Popup Dialogs


Conclusion

Opening a popup from a Ribbon Button in Dynamics 365 is a practical way to improve user interaction and streamline business processes. Using JavaScript and the Xrm.Navigation API, developers can easily launch web resources, custom pages, and entity forms in modal dialogs.

By implementing popup dialogs, organizations can reduce navigation, improve productivity, and provide a more user-friendly experience within Dynamics 365.