A JavaScript command on the case form deletes all draft activities linked to the case. Before deleting anything, the script must ask the user to confirm and must proceed only if the user agrees. Which implementation is correct?
Select an answer to reveal the explanation.
Short Explanation
openConfirmDialog doesn't freeze your code; it hands you a promise and an answer later. You wait for the answer, check confirmed, and only then do the destructive work, otherwise you've deleted the data while the user's still reading the question.
Full Explanation
Xrm.Navigation.openConfirmDialog displays a model-driven app confirmation dialog with confirm and cancel buttons and returns a promise. When the user closes the dialog, the promise resolves with an object whose confirmed property is true if the user chose the confirm button and false otherwise. The script must therefore put the deletion inside the resolution handler, or after an await, and check confirmed before calling Xrm.WebApi.deleteRecord for each activity. openAlertDialog only acknowledges a message; its single button gives the user no way to decline, so treating its closure as consent defeats the requirement. window.confirm is a browser dialog outside the Client API, it is not styled or localized with the app and can behave differently across hosts such as the mobile app, and the premise is false because Client API dialogs work from commands. Calling the deletion right after openConfirmDialog without waiting runs it immediately, because the dialog is asynchronous and does not block execution, so data is deleted before the user answers. Exam caveat: the dialog text, title and button labels can be customized through the confirm strings object. Operational check: run the command, select cancel, and confirm the activities remain, then run it again, select confirm, and confirm they are deleted.