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
Thank you very much Alex!
It works correctly now!
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.
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.
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156