Alert Dialog and Confirm Dialog in MSCRM 2013 Using Javascript

Especially Alert and Confirm Dialog designed for Mobiles/Tablets replacing window.alert and window.confirm.

It’s a best practice to use the new Syntax for Online/On premise as well.

Alert Dialog: Displays a dialog box like alert.

Syntax:

Xrm.Utility.alertDialog(message,onCloseCallback)
Parameter Name Type Description
message String The text of the message to display in the dialog.
onCloseCallback Function A function to execute when the OK button or Close button clicked.Use null if you don’t want callback.

Example: Set Personal Notes field with some text in Contact Entity Onload after Alert Click on Ok or Cancel/Close

Solution: Copy and paste the below Code in Contact Entity and call showAlertDialog on onLoad

function showAlertDialog() {
    Xrm.Utility.alertDialog("Click Ok or Cancel to set the Personal Notes Value", function() {
        Xrm.Page.getAttribute("description").setValue("alertDialog Fired");
    });
}

Output:

showAlertDialog
After Click on Ok or Cancel,

showAlertDialog Fired

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

Syntax: 

Xrm.Utility.confirmDialog(message,yesCloseCallback,noCloseCallback)
Parameter Name Type Description
message String The text of the message to display in the dialog.
yesCloseCallback Function A function to execute when the OK button is clicked.Use null if you don’t want callback.
noCloseCallback Function A function to execute when the Cancel button is clicked.Use null if you don’t want callback.

Example: Set Personal Notes field with some text in Contact entity Onload after Confirm Click on Ok or Cancel/Close

Solution: Copy and paste the below Code in Contact Entity and call showConfirmDialog on onLoad

function showConfirmDialog() {
    Xrm.Utility.confirmDialog("Click Yes or No to set the Personal Notes Value",
        function() {
            Xrm.Page.getAttribute("description").setValue("Yes Callback fired");
        },
        function() {
            Xrm.Page.getAttribute("description").setValue("No Callback fired");
        });
}

Output:

showConfirmDialog
Click on Ok to see the below result,

showConfirmDialog Yes

Click on Cancel or Close to see the below result,

showConfirmDialog No

Please provide your valuable comments on this article.

Advertisements

One thought on “Alert Dialog and Confirm Dialog in MSCRM 2013 Using Javascript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s