Hi!
Before the user leaves the form (Contact), either closes the form, close the window (web browser) or clicks in the menu I need to save some data to the entity.
My script is called from the OnLoad event of the form and it looks like this:
function SaveBeforeClosingForm() { window.onbeforeunload = function() { Xrm.Page.getAttribute("new_optionalstatus").setValue(100000001); Xrm.Page.data.entity.save(); return null; } }
It works fine the first time I open the form and closes it.
When I open it again I can see my change have been saved but when I try to close it the second time I get a Javascript error.
I don't see anything wrong in my code, it works the first time.
Any help out there?
*This post is locked for comments