06/02/2021

By Nikhil Rajendran | Reading time 6 mins

Configuring Different Actions for onClick of Cancel Button and X Button

Recently, I was given a requirement to develop a Xrm.Navigation.openConfirmDialog window. The interesting part of the requirement was that it was not meant to be used as the traditional dialog.

 

The traditional version generally has a “Ok” button and “Cancel” button. OnClick of the Ok button, we can configure some action. OnClick of the Cancel button or the X button, generally the requirement will be to close the dialog.

 

My requirement was slightly different.  I was asked to create a window that gives the user 2 different options. Both options have different business logic. The logic for on click of the Purchase Orders button must not be triggered on click of the X button.

 

Initially, my logic was like this:

Configure onClick of cancel button and X button - AhaApps
Configuring Different Actions for onClick of Cancel Button and X Button

15 Questions to Identify the Gaps in Your CRM

CRM Checklist - AhaApps

let confirmStrings = { confirmButtonLabel: “Invoice(s), cancelButtonLabel: “Purchase Orders”, text: “Select an option to generate invoice from.”, title:”Generate from”};

 

let confirmOptions = {height: 200, width: 450};

 

Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(

function (success)

{

if(success.confirmed)

{

// logic for on click of Invoice(s) button

}

else

{

// logic for on click of Purchase Orders button

}

});

 

The problem with the above logic is that the logic for on click of the Purchase Orders button will be triggered even if you click on the x button. The issue is that Dynamics 365 treats the Cancel(Purchase Orders) and X button as the same.

 

I started debugging the issue and found out that it was different when you click on the Cancel (Purchase Order) button and X button. It was the value of the confirmed attribute in success.

 

On Click of Purchase Orders,

success.confirmed = false.

on Click of the X button,

Success.confirmed was undefined.

Hence, I tweaked my code a little bit and met my requirement.

let confirmStrings = { confirmButtonLabel: “Invoice(s), cancelButtonLabel: “Purchase Orders”, text: “Select an option to generate invoice from.”, title: ”Generate from”};

let confirmOptions = {height: 200, width: 450};

Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(

function (success)

{

if(success.confirmed)

{

// logic for on click of Invoice(s) button

}

else if(success.confirmed != ‘undefined’)

{

// logic for on click of Purchase Orders button

}

Else

{

//Logic for on click of the x button

}

});

 

You can use the above logic to deal with situations where you need to have different logic for on click of the Cancel button and X button in Xrm.Navigation.openConfirmDialog

To know more about such solutions in Dynamics 365, do connect with us.

Author’s bio:

Nikhil has been with AhaApps since 2017 as a Microsoft Dynamics CRM Developer. He is a driven CRM expert who is ready to fight off the challenges in the Dynamics world with his technical know-how and prowess. He is a sports enthusiast and loves to play tennis when he gets time. He is also a voracious reader and enjoys reading philosophical books.

How To Use Advanced Find in Dynamics CRM 365

For an entity, in Dynamics 365, if there is a frequently used query that can be set up as the default query. This will help the users save some time