How to Show Confirm Dialog Box using Javascript?

How to Show Confirm Dialog Box using Javascript?

Using openConfirmDialog you can display a confirmation dialog box containing a message and two buttons.

Here is a method to display confirm dialog:

Xrm.Navigation.openConfirmDialog(confirmStrings,confirmOptions).then(successCallback,errorCallback);

Example:

In this example, open ConfirmDialog Box on Save Record and show Alert on Success Event.

Step 1: Open Code Editor and Create New Javascript File.

The following code sample displays a confirmation dialog box. An appropriate message is shown in the Alert Dialog Box depending on whether confirm or cancel was clicked to close the dialog.

var confirmStrings = { text:"Do you want to save Record?.", title:"Confirmation" };
var confirmOptions = { height: 200, width: 450 };
Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
function (success) {
if (success.confirmed)
alert("success.");
else
alert("Cancel.");
});

In the function (success) block you need to define what you want at success.

Step 2: Create a new Webresource type of JScript(javascript).

Create a new Webresource

Step 3: In the Web Resource dialog box give the appropriate name, display the name and select type as Script(JScript), and select a file. Then Click Save and Publish.

Web Resource dialog box give the appropriate name

Step 4: Select the entity Form where you want to show Confirm Dialog Box. and open the Main Form of Entity.

Show Confirm Dialog Box

Step 5: In Entity Main Form Select Form Properties.

Main Form Select Form Properties

Step 6: From Form Properties Dialog Box, click on + Add Button.

From Form Properties Dialog Box

Step 7: After selecting Add it will open LookUp Record Dialog Box. in LookUp Record Dialog Box Search Webresource and select WebResource then click on Add.

LookUp Record Dialog Box

Step 8: After that in the Event Handler section select

Control = Form

Event = OnSave

Next Click Add.

Event Handler section select Control Form

Step 9: After that, it will open the Handler Properties dialog box. Enter the Appropriate Function Name that is written in your Webresource code and Then click Ok.

Handler Properties dialog box

Step 10: After that Click Save and Publish.

Click Save and Publish

Step 11: Redirect to Entity and try to create a new record then Click on Save Button. It will open the Confirmation Dialog Box. click on OK and it shows Alert Box.

Redirect to Entity and try to create a new record 1

Redirect to Entity and try to create a new record 2

On click of the OK button, it will show the message which we have written on successcallback method of confirm dialog.

So this is how users can configure confirm dialog in CRM.

 

All product and company names are trademarks™, registered® or copyright© trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Riddhi Faldu

Riddhi Faldu

Riddhi is a firm believer of serenity and writing is something that keeps her grounded. Being a Computer Engineer by qualification, understanding and writing about tech comes to her naturally. It wouldn't be wrong to call her diligent as she likes pushing herself and others to bring the best on table. In leisure time, she likes practicing calligraphy and wishes to master the beautiful concoction of ink and words.

Read Related Blogs About Dynamics 365 Portal

How to Clear the Cache in the Power Apps Portal

How to Clear the Cache in the Power Apps Portal

3 Min
Revolutionizing Financial Services with Dynamics 365 Customer Portal

Revolutionizing Financial Services with Dynamics 365 Customer Portal

5 Min
Why You Need D365 Developers in Your Team

Why You Need D365 Developers in Your Team

4 Min
To Top