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)
Answered

Set Date as today using business roles

(0) ShareShare
ReportReport
Posted on by

Hi All, 

i just need the simplest way to set a date field to be NOW when another field's value changes 

i prefer if there is a way using business rules. 

Your help is appreciated 

Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mithilesh Kumar Profile Picture
    10,047 on at

    Hi

    Business Rule does not have any operator which check if the field value has changed.

    You need to use JScript to change the field value. Use this script on the OnChange event of the field.

    function FieldValueChange(){
     Xrm.Page.getAttribute("new_todaydate").setValue(Date.now());
    }

    Hope that helps

    Thanks

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi Alaa,

    You cannot set the current date using Business Rule, there is no operator set value based on today date in CRM 2013, yes, you need a javascript.

    Thanks.

  • Community Member Profile Picture
    on at

    Is there any way to compare date field with todays date in business rule an then set Action ?

    Regards,

    Kamran

  • Suggested answer
    Community Member Profile Picture
    on at

    You can accomplish this using the workflows rather than the 'Business Rule' option:

    - Create a workflow and set which field changes it triggers on - I don't think it needs to be synchronous for your needs?

    - Choose to update the record, and populate the relevant field using the options shown below to put in the process execution time.

  • Suggested answer
    Jharana Baliyar Singh Profile Picture
    2,667 on at

    Hi AllaMoh,

    There is no way for your requirement using business rules,For this You have to write Javascript Onchange,You can see below code:

    var currentDateTime = new Date();

           var millis = currentDateTime.getTime() + (currentDateTime.getTimezoneOffset() * 60000);

           currentDateTime.setTime(millis);

           Xrm.Page.getAttribute(fielName).setValue(currentDateTime);

    Try on this,may it will help you.

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at

    you can set a RT workflow that its trigger is the change of the field

    the value that will be implemented is the execution date&time of the workflow

  • Community Member Profile Picture
    on at

    Is this issue fixed in 2015 ?

  • Verified answer
    Aerick Profile Picture
    75 on at

    [quote user="Mithilesh Kumar"]

    Hi

    Business Rule does not have any operator which check if the field value has changed.

    You need to use JScript to change the field value. Use this script on the OnChange event of the field.

    function FieldValueChange(){
     Xrm.Page.getAttribute("new_todaydate").setValue(Date.now());
    }

    Hope that helps

    Thanks

    [/quote]

    This code worked beautifully for me, though I did need to add:

    Xrm.Page.getAttribute("[fieldname]").setSubmitMode("always");

    In order for my form to save the value in the field I was updating (a read-only date/time field).

  • Tuan Profile Picture
    65 on at

    Agree with AlaaMoh89 this should be fixed by MS. Something simple like: when there's no datetime specified in Value, the default datetime is Now datetime.

  • Suggested answer
    Community Member Profile Picture
    on at

    You can simulate onChange events in your business rules or calculated fields with some creativity.

    Mind that this only works if you want the datetime field to be populated based on one field changing, if you want it to run on multiple possible field changes, it wont work and I wouldnt recommend using below method, because it will create an overkill on fields.

    If there is just one field however, you can copy the old field’s value to a new field (both fields should be of the same type) with a workflow on change of the old field (before change). Create a Calculated Date-Time field, which states if new value of old field does not equal the value of the new field (=change) set the datetime to Now().

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