[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1101
  • Last Modified:

OnChange Script in CRM to update a date field

I need an OnChange Script that will update a date/time field to the current date.

i.e.  when field1 is changed, update field2 to the current date.
1 Solution
Add the script, below, to the OnChange event for field1.  To that:
(1) Settings
(2) Customization
(3) Customize Entities
(4) Choose the entity that you wish to customize and double-click
(5) Select Forms and Views
(6) Double-click on the form
(7) Navigate to field1
(8) Double click
(9) Click the Events tab
(10) Click the Edit button
(11) Paste the script below (edited to replace field2 with the name of your field)
(NOTE: you can add to the year, month or date to change the date it creates; NOTE2: the script below sets the time to 8:30am)
(12) Test if you wish (use the preview button at the top of the form designer)
(13) Click OK and Save and Close until you get back to the list of entities.
(14) Click the Publish button while on the entity in question
(15) All done

var today;
today = new Date();
crmForm.all.field2.DataValue = new Date(today.getYear(), today.getMonth(), today.getDate(), 8, 30);

Open in new window


Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Tackle projects and never again get stuck behind a technical roadblock.
Join Now