Custom dialogs in Model Driven Apps πŸ’‘πŸš€

Custom dialogs in Model Driven Apps πŸ’‘πŸš€

Β·

5 min read

#1. Introduction - Deprecated dialogs

Do you still know the old dialogs, which have unfortunately been deprecated for years? πŸ€”

https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/understand-dialogs?view=op-9-1

Source: https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/understand-dialogs?view=op-9-1

It was a very good way to guide users through a process. The user could select different values and based on this, different scenarios could be mapped, such as a case creation, which requires different data from the user as input depending on the selection.

Since the function should no longer be used, there must be a new way to replace this function, or even a better one! Something like that exists. πŸ˜‰

#2. Target

Our goal is to create a dialog within Model Driven Apps, empowering users to carry out system-controlled processes. By aligning processes with user actions, we make it easier for users to maintain accurate data 🎯, saving time ⏱️ and delivering valuable results πŸ’ͺ. This has a tangible impact on departments like marketing or service, as better data enables more targeted and successful marketing campaigns or a better case resolution. πŸ“ˆ

In this blog article, for the sake of simplicity (please forgive me πŸ™), I do not create a process dialog, but therefore replace a dialog that is provided by the Microsoft standard. The talk is of "Close As Won" in the opportunity form.

So many customers have asked me if this dialog can be modified. Yes❗, it's very easy to do, by ticking a box βœ… in the settings βš™οΈ and editing the quick create form for opportunity close, but honestly, is that nice? πŸ’©

#3. Implementation

#3.1 Create a canvas page

First, you need to create a canvas page that will later be shown as a modal.

Like this:

Yeah, I know ... I have only removed the competitor, but trust me (❗) customers have many ideas of important data depending on their businessπŸ’‘.

When the page is created, and is more or less beautiful (I hope more πŸ˜‰), then you have to add logic to the page.

There are some things to do and I will show them all very quickly πŸƒ:

  1. Screen - OnVisible

    OR

    App - OnStart

     Set(varRecord, LookUp(Opportunities, Opportunity = GUID(Param("recordId"))))
    

    ➑️ This code snippet is used to retrieve the opportunity record

  2. Submit (OK) button βœ…

     // Show a loading spinner to indicate that something is happening
     Set(varLoadingSpinner, true);
    
     // Run a flow for further changes based on the input
     'YOUR FLOW'.RUN(
    
         // pass the arguments you need for your process
    
         varRecord.Opportunity,
         DropdownCanvas_StatusReason.Selected.Value
    
         //    ...    add more :-)
     );
    
     // Hide the loading spinner
     Set(varLoadingSpinner, false);
    
     // Close the dialog
     Back();
    

    ➑️ This code snippet is used to display a spinner when calling or executing a flow. The flow is not necessary, you could just write the logic in PowerFx, but with flow there are also possibilities e.g. to send data to external systems like an ERP system. πŸ’‘

  3. Cancel button ❌

// Go back and do nothing
Back();
  1. Remember your canvas page name after saving, you'll find it in your solution. πŸ”Ž

#3.2 Create a JavaScript

Now you have to create the JavaScript to call the dialog.

function OpenCloseOpportunityDialog(formContext) {

        var pageInput = {
            // open a custom canvas page - do not change this
            pageType: "custom",

            // replace "YOUR_APPNAME" with your app name
            name: "YOUR_APPNAME",

            entityName: formContext.data.entity.getEntityName(),
            recordId: formContext.data.entity.getId()
        };

        var navigationOptions = {
            // open as dialog
            target: 2,

            // centered
            position: 1,

            width: { 
                // change this based on your page width
                value: 400, 
                unit: "px"
            },
            height: { 
                // change this based on your page height
                value: 560, 
                unit: "px" 
            }
        };

        Xrm.Navigation.navigateTo(pageInput, navigationOptions)
            .then(
                function () {
                    // reload, because it could be closed by your process
                    formContext.data.refresh(true);
                }
            ).catch(
                function (error) {
                    console.log(error.message);
                }
            );
    }

#3.3 Create a custom command button

In order to be able to call the newly created function to open the dialog, you must create a new command button.

If you don't know how this works, please check my blog post about How to populate data into navigateTo() β“βœ….

And please remember...

⚠️ Don't forget to set "PrimaryControl" as your first parameter!!!

If you don't want the "old" button to be visible, just open the good old Ribbon Workbench and hide it. If you don't know how to use it: click here to get wisdom.

In this case, I was only allowed to display the button when the opportunity was in the "Open" state, so I had to define a visibility expression.

If(Self.Selected.Item.Status = 'Status (Opportunities)'.Open, true, false)

#3.4 Don't forget to add the page to your Model Driven App

I have already wasted a lot of time trying to find the reason why my dialog was not displayed. Each time I had not added the page to the Model Driven App. Be smarter than me and add it immediately.

#3.5 Result

As a result, we have the finished dialog. It wasn't that difficult, was it? 😎

In conclusion, through this little example, we have demonstrated the capability of the Power Platform to enable the creation of dialogs within Model Driven Apps using simple yet powerful tools. πŸ’ͺ

Maybe my example is not that useful πŸ’©, but the goal was to show that such a thing is possible βœ…. What you do with it, and how you use the instrument, is another story. πŸš€

If you have any cool ideas that can be presented through dialogs, please let me know! πŸ˜›

Feedback is absolutely welcome! 🫑

Did you find this article valuable?

Support Nils Goldenstein by becoming a sponsor. Any amount is appreciated!

Β