Prevent Save with openConfirmDialog – executionContext.getEventArgs().preventDefault() and Xrm.Navigation.openConfirmDialog
There are times we might need to have a confirmation dialog before saving the record and in the case of cancel, needs to refresh the form data to previous state. Confirmation dialog is achievable using the client side SDK scripts. It is pretty easy to put the confirmation dialog in the save event, the tricky part is how to prevent saving and resetting the old data when confirm dialog is cancelled.
The below code help to make use of the save event functions to better use and achieve the need.
function onSave(executionContext) { var depth = sessionStorage.getItem("depth"); if(depth == null || depth == "0"){ console.log("Depth - "+ depth); sessionStorage.setItem("depth", "0"); var formContext = executionContext.getFormContext(); executionContext.getEventArgs().preventDefault(); var tagMetaData = []; const tagNames = []; var xml = formContext.data.entity.getDataXml(); var node = (new DOMParser()).parseFromString(xml, "text/xml").documentElement; var nodes = node.querySelectorAll("*"); if(nodes.length > 0){ for(let i = 0; i < nodes.length; i++) { if(nodes[i].getAttribute("type")…
View original post 133 more words