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 Field Value onLoad and when the value is deleted ----- Javascript

(0) ShareShare
ReportReport
Posted on by 274

I have a calculation field, I am using business rule to calculate the total onSave. I am using JavaScript onLoad to set the default field values to 1.00.  The below code works fine onLoad, however onChange it doesn't set back the value back to 1.00. The only time the value need to be set to 1 is onLoad and if the user delete the value. For instance If a user put 10 for one of the field, onSave the total will be calculated. However if they decided to delete the value of the field  I want it to be set to 1.00. The below code set it to null. Thanks!!

function onLoad() {
   Test("new_field1");
}
function new_field1OnChange() {
   Test("new_field1");
}
function Test(fieldName) {
   if (Xrm.Page.getAttribute(fieldName).getValue() == null) {
       Xrm.Page.getAttribute("new_field1").setValue("1.00");
   }
   else {
       Xrm.Page.getAttribute("new_field1").setValue("");
   }
}


*This post is locked for comments

I have the same question (0)
  • Felippe Profile Picture
    796 on at

    Hi MituCRMing,

    The field in case it's a  Business Required field?

    At some versions of CRM ( 2013+ i think) for the required fields, the onChange event is not fired when the user empties the field.

    If you can, remove the requirement business for this field, and try to set the requirement rule  via Javascript.

    This case have been already discussed at:

    community.dynamics.com/.../113794

    Best Regards,

    Felippe Mendonça dos Santos

    If this help you, please "Like" and "Mark as Answer"

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