We have a custom entity where we need to check, on the attempt to save a record, if a particular set of conditions is true (querying other records, etc...). If it isn't, it should just save normally. If it is, then we want a prompt to come up, giving them some information, and confirming whether they want to save or cancel.
I've got a function triggering onSave, and it's checking my conditions without problem. I have alert.js loaded to bring up the prompt, and have the buttons, the functions, etc... However, if I bring up a prompt through alert.js, it's still going ahead and saving the record in the background, before I can answer the prompt. I could put a wait timer or something, but then if they take longer than that it will still happen, etc...
I thought perhaps I could cancel the save at the start of the function with getEventArgs().preventDefault(), do the checks, and then use xrm.page.data.save() to go ahead with the save only when they say to do (or when the conditions are not met). I worried that this might loop, but figured I'd test it. It's definitely not looping, because the save is failing (i.e. it's hitting the failure callback function). But I'm getting no messaging in CRM about why the save would fail, and if I take out the preventDefault call, the record is able to be saved with no difficulty. So I'm guessing perhaps the preventDefault call is setting some sort of flag that's keeping the record from saving even after I manually call the save again.
Any way to clear that flag (if it exists), or any other way to go about this problem?
Thanks!
*This post is locked for comments