How to set a value to IsDirty form method
-
Sunday, January 03, 2010 6:21 PMHello all,
I have just made some customizations in email form. (load event javascript)
But now when I choose options to convert it to opportunity or activity I get message first save data before continuing, checking javascript logic I see that this message appears when isDirty method returns true, How can I set this value to false ?
Yojan
All Replies
-
Sunday, January 03, 2010 6:50 PMIsDirty is a property and not a method, so you can set this property to false by using the folowing code.
crmForm.IsDirty=false; -
Sunday, January 03, 2010 9:02 PMThanks for reply ....
But when I try to do what ever action for example save or convert to oportunity now I get javascript error. This happens after I set crmForm.IsDirty=false; as last sentence on load form event
Has anyone done something similar ?
Regards
Yojan -
Monday, January 04, 2010 5:38 AMHi Yojan,The IsDirty property of CrmForm is readonly one, we can't set its value, if we try to do so we would get the following error"Object does not support this property or method."If you are getting form not saved information while converting email , one thing you could do is to try debugging the existing JavaScript on you email form. Try by disabling and enabling script one by one for different attributes or form. This might help to find the reason for that issue.Regards,Nishant Rana
http://nishantrana.wordpress.com -
Monday, January 04, 2010 8:10 AMI'm guessing that your customizations are javascript and modifying the field values on your form. In this case you should try to work out some logic to only update value when needed. Not every time.
If you're not updating any field values then are you using the "ForceSubmit" switch on any attributes? I think this sets the isDirty property too. -
Monday, January 04, 2010 3:01 PMModerator
The value of IsDirty is calculated by comparing the values of the DataValue and defaultValue properties. So, to set IsDirty to false, you could use:
crmForm.all.<fieldname>.DataValue = crmForm.all.<fieldname>.defaultValue;
Note that the ForceSubmit property does not actually set the IsDirty property. Instead it is also checked when validating the form, but you can directly set it to false.
Microsoft CRM MVP - http://mscrmuk.blogspot.com http://www.excitation.co.uk- Marked As Answer by Yojan Monday, January 04, 2010 4:23 PM
-
Monday, January 04, 2010 4:23 PMThanks DavidJennaway ,
This exactely solved my problem.
Making some customization onLoad event and adding this sentece afterwards:
crmForm.all.<fieldname>.defaultValue = crmForm.all.<fieldname>.DataValue
Regards
Yojan -
Thursday, February 02, 2012 11:31 AMbut for lookup datafield it is not working
-
Wednesday, June 13, 2012 12:23 PM
This method is only working for fields containing string values. It does not change the IsDirty-flag because defaultValue is a string.
But why is that?
So this is not working:
function resetIsDirty(fields) { for (var i = 0; i < fields.length; i++) { if (fields[i].DataValue) { fields[i].defaultValue = fields[i].DataValue; } } return fields; };
How can we avoid the crmForm.detachCloseAlert()-method and have a granular control over the IsDirty-value?
Regards
-
Friday, June 15, 2012 2:04 PM
Here's the solution to prevent detaching the whole form validation due to modification:
function resetDirtyFields() { crmForm.detachCloseAlert(); var iLen = crmForm.all.length; for (var i = 0; i < iLen; i++) { var o = crmForm.all[i]; if (o.tagName == 'INPUT') { o.attachEvent('onchange', function () { window.onbeforeunload = function () { if (crmForm.IsDirty()) { event.returnValue = "Changes will get lost."; return false; } }; }); } } }
-
Monday, June 18, 2012 12:28 PM
As my code above alerts the user while saving the record when the form is dirty.
Here's the solution that works without that issue:
function resetDirtyFields() { crmForm.detachCloseAlert(); //declare gobal variable to store information about the save event
isSavingAction = false; crmForm.attachEvent('onsave', function () { isSavingAction = true; }); var iLen = crmForm.all.length; for (var i = 0; i < iLen; i++) { var o = crmForm.all[i]; if (o.tagName == 'INPUT') { o.attachEvent('onchange', function () { window.onbeforeunload = function () { if (!isSavingAction) { if (crmForm.IsDirty()) { event.returnValue = "Changes will get lost."; returnfalse; } } }; }); } } }