Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM - Confirm DIalog ( OK / CANCEL ) pop-up again after i click Cancel option

Posted on by 150

Hello everyone,

I created a simple javaScript which throw a Confirm Dialog which fire on change the value of a pick list field.

When I execute it, the confirm dialog appears and if i click cancel it appears 2 more times until finally it performs the action required.

How can i fix it and ensure that it only appears once?

Kind regards,

below you can see my code

function ConfirmationDialog(){
var ValueSelected = Xrm.Page.getAttribute('gri_sustainabilityreportstatus').getValue();
debugger;
if (ValueSelected == 172340000 || ValueSelected == 172340001 || ValueSelected == 172340003){

Xrm.Utility.confirmDialog("This option will send a email.", function(){
// Callback that happens when user clicks OK
return;
}, function(){
// Callback that happens when user clicks Cancel.
Xrm.Page.getAttribute('gri_sustainabilityreportstatus').setValue(null);
return;
});
}
else{
return;
}
}

*This post is locked for comments

  • Jorge Gomez Profile Picture
    Jorge Gomez 150 on at
    RE: CRM - Confirm DIalog ( OK / CANCEL ) pop-up again after i click Cancel option

    Thank you very much Alex!

    It works correctly now!

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: CRM - Confirm DIalog ( OK / CANCEL ) pop-up again after i click Cancel option

    Try moving your code to the setTimeout like this - worked for me:

    function ConfirmationDialog(){

    setTimeout(function()

    {

     <YOUR CODE HERE>

    }, 10);

    }

    The problem is that you are changing that value inside "onchange" handler, so onchange fires again, however, since it's all happening synchronously, when you call "getValue" it's still giving you some value (not null yet). Eventually, it gets through.. but it seems to require a few cycles.

  • Jorge Gomez Profile Picture
    Jorge Gomez 150 on at
    RE: CRM - Confirm DIalog ( OK / CANCEL ) pop-up again after i click Cancel option

    Yes i know it, that is the functionality desired.

    But it took 3 loops to set it. What i mean is:

    Select value 1

    pop-up dialog ( the value is 1)

    click cancel

    pop-up dialog ( the value is still 1)

    click cancel

    pop-up dialog( the value is still 1)

    click cancel

    the value switch to null, the pop-up dialog does not appear anymore.

  • Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: CRM - Confirm DIalog ( OK / CANCEL ) pop-up again after i click Cancel option

    Hi

    This is because, you are changing  the value for the attribute gri_sustainabilityreportstatus, in the Cancel callback function.

    Please check the value of the optionset second time, when you set null

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans