web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Confirm dialog in model driven

(0) ShareShare
ReportReport
Posted on by 595

I wan't to show like conform dialog box when an user change an optionset field value in form .. only when he choose "ok" then only that field should update if choose "cancel" it should not update... How can i achieve this in model driven... Please give some suggestions....

*This post is locked for comments

I have the same question (0)
  • Verified answer
    meelamri Profile Picture
    13,216 User Group Leader on at

    Hi, 

    you can use JavaScript code for this scenario. 

    var confirmStrings = { text:"This is a confirmation.", title:"Confirmation Dialog" };
    var confirmOptions = { height: 200, width: 450 };
    Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
    function (success) {    
        if (success.confirmed)
            console.log("Dialog closed using OK button.");
        else
            console.log("Dialog closed using Cancel button or X.");
    });

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-navigation/openconfirmdialog

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Abhilash,

    We can use Xrm.Navigation.openConfirmDialog function to invoke a modal dialog.

    For confirmation logic, we should create a global variable in js library to save previous value of option.

    If choose "ok", only set variable to value of current selected option.

    If choose "cancel", set current option with variable, then update variable to value of current selected option.

    1. Run onFormLoad function at form OnLoad event, it is used to get initial value of optionset field.

    pastedimage1594284264566v2.png

    2. Run onFieldChange function at the optionset field OnChange event.

    pastedimage1594284286801v3.png

    3. The JScript web resource code.

    var previousValue;
    
    function onFormLoad(executionContext) {
      var formContext = executionContext.getFormContext();
      previousValue = formContext.getAttribute("preferredcontactmethodcode").getValue();
    }
    
    function onFieldChange(executionContext) {
      var formContext = executionContext.getFormContext();
      var confirmStrings = { title: "Optionset update", text: "Are you sure to change it?", };
      var confirmOptions = { width: 450, height: 200 };
      Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
        function (success) {
          if (success.confirmed) {
            previousValue = formContext.getAttribute("preferredcontactmethodcode").getValue();
          } else {
            alert(previousValue);
            formContext.getAttribute("preferredcontactmethodcode").setValue(previousValue);
            previousValue = formContext.getAttribute("preferredcontactmethodcode").getValue();
          }
        });
    }

    Test:

    The value of initial option is 4.

    pastedimage1594284366656v4.png

    If I choose Ok, then Email(2) will be set to variable as previous value, the field will be set to new selected option directly.

    pastedimage1594284410511v5.png

    If I choose Cancel, the debugging alert will tell me the previous option is Fax(4), and the field will be rolled back to Fax(4).

    1854.pastedimage1594284470719v6.png

    You could keep alert to test whether my code works for you(It works well from my test),

    then remove the statement if it passes your test.

    Regards,

    Clofly

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans