
Hi,
I have this JavaScript to set default values for a text field and it works as expected, displaying what I want to see in the field when I create a new record. When a user initally creates a record, fills in the text field, then saves the record, it clears everything the user entered and refreshes to that default value. However, when the user Saves & Closes the record and re-opens the record, the information the user entered remains. How do I modify the code below to NOT refresh the field and leave any information the user entered intact? Thanks.
function prefilledField(fieldName, value) {
var isCreateForm = Xrm.Page.ui.getFormType() === 1;
var field = Xrm.Page.getAttribute(fieldName);
if (isCreateForm) {
field.setValue(value);
field.setSubmitMode("always");
}
}
*This post is locked for comments
I have the same question (0)Need some more info, like what are the triggering points for this function to give a better suggestion. Based on my understanding,
In the If condition, check whether the field has value in it or not,
if(isCreateForm && field.getValue())
Make sure the function is called onload of formand in onchange of the field. Do not register on onsave. I will not touch setSubmitMode until the field is readonly. If the same logic is needed on update form, update the form type condition to include update form.
Note:
1. This is fairly straight forward and a simple business rule/workflow could do.