The other day I was writing some JavaScript code that would update a field value on a form for an aggregate of 2 field values from a different entity. I wrote some fetchxml that would get the values and then sum them up. I then would set the value to a read-only field on my original form. It all works great until you try to close the form without doing any changes or saving. You get the standard CRM 4.0 warning about you not saving the form with changes. Well the issue is I didn’t make a change the onLoad code did. So what I wanted was to prevent the message from showing. I found a very good blog that was written by Geron Profet (
Here is what you will need to add to your onLoad script to prevent the alert message from showing.
if(crmForm.all.<your fieldname>.IsDirty){ |
crmForm.detachCloseAlert(); |
} |
The nice thing here isthat by using the isDirty() function you will only detach the close alert if that field changes. The alert will still show if other fields change and you forget to save. Bug solved! Remember that crmForm.detachCloseAlert() is not a supported solution from Microsoft.
Post by: Jeff Macfie,