web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Setting Default Value for Text Field

(0) ShareShare
ReportReport
Posted on by

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)
  • ram r Profile Picture
    on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans