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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans