OnChange Script in CRM to update a date field

Posted on 2009-04-28
Last Modified: 2013-11-24
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.
Question by:jgould763
    1 Comment
    LVL 10

    Accepted 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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I showed you how to use console view (HERE ( -– but how do you set it up on the admin side of Salesforce? Note that you have to have Admin leve…
    Note: You must have administrative privileges in order to create/edit Sharing Rules. ( (SFDC) is a cloud-based customer relationship management (CRM) system. It is a database most commonly used by sales an…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now