What is the Issue?
Sometime user saves the record, even after saving the crm shows unsaved changes on form. Also if we try to “save and close/Close” the current saved record the popup continues with message – “Unsaved changes on form”.
The Reason-
This causes due to –
1. Some JavaScript is setting the field value on ‘onLoad’ event of form.
2. Some Business Rule is setting the field value.
3. Some field/fields are locked on form and populating through script.
Solution-
To solve this issue –
1. If JavaScript function is the reason, then add check condition-
if (Xrm.Page.ui.getFormType() == 1) {
//populate your values
}
// formType=1 is for Create record
This will populate the values in fields only first time i.e. the record is not saved yet.
2. If Business Rule is the reason, then add check condition before populating values-
IF Created On does not Contains Data
Then populate values
The created On field contains data only for existing/saved records and this field
populates only once,on first save of record.
3. If some fields are locked on form and populated through javaScript-
The problem is the read only fields are not consider for saving in CRM automatically. There are 3 modes for saving the read only fields-
- always: The value is always submitted.
- never: The value is never submitted. When this option is set, data cannot be edited for any fields in the form for this attribute.
- dirty (default): The value is submitted on create if it is not null, and on save only when it is changed.
You can save the read only field using setSubmitMode function as-