Tags

, , , , , , ,

Hello Everyone,

The two dialog boxes (Alert and Confirm) have been around in Dynamics CRM for quite long and I still use them regularly in the jScrip. The earlier windows.alert / windows.confirm will be deprecated in the Dynamics 365 mobile client and recommended to use Xrm.Utility.alertDialog / Xrm.Utility.confirmDialog instead, more details in the MSDN article here.

 

AlertDialog:

Displays a dialog box containing an application-defined message.

Xrm.Utility.alertDialog(message,onCloseCallback)

Parameters:

Name Type Required Description
message String Yes The text of the message to display in the dialog.
onCloseCallback Function No A function to execute when the OK button is clicked.

 

The sample code which I use:

Xrm.Utility.alertDialog(“Email should not be left blank!”,function(){return;});

 

 

ConfirmDialog:

Displays a confirmation dialog box that contains an optional message as well as OK and Cancel buttons.

Xrm.Utility.confirmDialog(message,yesCloseCallback,noCloseCallback)

Parameters

Name Type Required Description
message String Yes The text of the message to display in the dialog
yesCloseCallback Function No A function to execute when the OK button is clicked.
noCloseCallback Function No A function to execute when the Cancel button is clicked.

 

 

The sample code which I use:

Xrm.Utility.confirmDialog(

“Opportunity Close Date should not be left Blank. Update the close date?”,

function() {
Xrm.Page.ui.controls.get(“header_process_ashwin_oppclosedate”).setFocus();
} ,

function() {
var TodaysDate= new Date(); // Get Today’s current date
Xrm.Page.getAttribute(“ashwin_oppclosedate”).setValue(TodaysDate);
}

);

 

In the above code, I want to make sure the OppCloseDate shouldn’t be left blank. I’ll set the focus of the field to update if the user clicks the button OK. Else if the user selects Cancel, I’ll default it to today’s date.

 

I’m pinning this down as a day to day useful scripts during development considering the Dynamics 365 mobile client as well. Hope that would be helpful. Thanks ! 🙂