SBX - Search With Button

SBX - Forum Post Title

Date field with today's date

Microsoft Dynamics CRM Forum

maggie cham asked a question on 17 Feb 2016 10:11 AM

Question Status

Verified

Hello,

I would like to have a field that will display the current date at any given time, effectively the same as having the TODAY() function in Excel. Is there a way to do that without script?

Many thanks,

Reply
Sean Kelly responded on 17 Feb 2016 10:43 AM
My Badges
Verified Answer

Hi Maggie,

You could achieve this with a Calculated field.

First create a new field with a Field Type of Calculated

Then click Edit next to Field Type, leave the condition blank and for the action have it as "Set Todays Date to Now()"

Now place the field on your form and when you open the form it will show todays date

Reply
maggie cham responded on 19 Feb 2016 10:35 AM

Hi Sean,

Thanks for that.

It appears as if calculated fields don't work in business rules. Is there a way to get today's date without a calculated field?

I would like to use today's date in a business rule that will set as business required another field based on whether a record was created 14 days or prior to today.

Many thanks,

Maggie

Reply
Raz Dynamics responded on 19 Feb 2016 12:52 PM
Suggested Answer

Hi Maggie, You can use a Realtime Workflow

Set the Executin Date and Time of workflow and insert it into required field.

- add update record step into workflow

- go into Properties

- add Execution date and Time into Required date Field.

when the workflow runs it inserts the current Date and Time into this field.

I Hope this helps, Kindly tick 'Yes' to verify :)

Best Wishes, Raz

Reply
Mahender responded on 20 Feb 2016 12:50 AM
My Badges

Another option to use script but it will only run when you will open entity form.

Thanks

Reply
maggie cham responded on 22 Feb 2016 7:48 AM

Hi Raz,

What will trigger the workflow to run though? Will I have to run it manually everyday?

I need the field to show the current date when someone opens the record, so this needs to change everyday.

Many thanks,

Reply
PaulShore responded on 5 Sep 2016 9:57 AM
My Badges
Suggested Answer

Sean's solution answered your original question!

"It appears as if calculated fields don't work in business rules. Is there a way to get today's date without a calculated field?

I would like to use today's date in a business rule that will set as business required another field based on whether a record was created 14 days or prior to today."

1. Create a simple DateTime field, lets call it new_todaysdate

2. Add the below javascript as a JS web resource for your solution. Call the Web resource something like new_SetTodaysDate or whatever convention you prefer.

function SetTodaysDateOnLoad(){
 Xrm.Page.getAttribute("new_todaysdate").setValue(Date.now());
}

Save, and publish.

3. In your solutions editor, click 'Form Properties' in the entitiy's form you're working with.

4. In Event List, add the new JS resource.

5. In Event Handlers add the function name SetTodaysDateOnLoad 

(Don't add brackets after the function name here)

 

Save and publish and you have the field with today's date accessible in a business rule.

Make sure this field is invisible in your form, or even make it immutable straight after onload and mutable again after updating with the help of a workflow.

Reply
Daniel at VNS responded on 8 Dec 2016 11:33 PM
My Badges
Suggested Answer

Thank you PaulShore - THIS is what i was looking for!

Reply
Bill Ames responded on 13 Feb 2017 12:57 PM

Where Sean's answer will do what you need it to, it will not however display a date on the form while creating.  The calculated field will not calculate until after saving.  That goes for workflows as well.  The run "Before" option is disabled in real-time workflow.

Reply
iruser2 responded on 28 Jun 2017 1:30 PM
My Badges

i'd love to find a way to have a date field on a form that automatically populates with todays date (and can still be changed by the user) without having to save in order to trigger a work flow.  The original question does CRM have the equivalent of excel

=TODAY()

that it can automatically populate onto a form without saving, just be there as the form opens?

thanks!

Reply
Adam Travers responded on 17 Nov 2017 3:50 AM
My Badges

Just hit upon this myself and this solution worked well for me. Thanks Sean Kelly.

Reply
Dimitri Olympios responded on 21 Mar 2018 5:55 AM
My Badges

Thank you Paul Really Helpful!

Reply
CRM Trickey responded on 20 Jun 2018 7:44 AM
Suggested Answer

I'd just set the date to be the ModifiedOn using a Set Value Action. Since the Business Rule will be invoked manually this worked in my scenario.

Reply
Dik Van Vliet responded on 13 May 2019 6:05 AM

=NOW()

Reply
Sean Kelly responded on 17 Feb 2016 10:43 AM
My Badges
Verified Answer

Hi Maggie,

You could achieve this with a Calculated field.

First create a new field with a Field Type of Calculated

Then click Edit next to Field Type, leave the condition blank and for the action have it as "Set Todays Date to Now()"

Now place the field on your form and when you open the form it will show todays date

Reply
Raz Dynamics responded on 19 Feb 2016 12:52 PM
Suggested Answer

Hi Maggie, You can use a Realtime Workflow

Set the Executin Date and Time of workflow and insert it into required field.

- add update record step into workflow

- go into Properties

- add Execution date and Time into Required date Field.

when the workflow runs it inserts the current Date and Time into this field.

I Hope this helps, Kindly tick 'Yes' to verify :)

Best Wishes, Raz

Reply
PaulShore responded on 5 Sep 2016 9:57 AM
My Badges
Suggested Answer

Sean's solution answered your original question!

"It appears as if calculated fields don't work in business rules. Is there a way to get today's date without a calculated field?

I would like to use today's date in a business rule that will set as business required another field based on whether a record was created 14 days or prior to today."

1. Create a simple DateTime field, lets call it new_todaysdate

2. Add the below javascript as a JS web resource for your solution. Call the Web resource something like new_SetTodaysDate or whatever convention you prefer.

function SetTodaysDateOnLoad(){
 Xrm.Page.getAttribute("new_todaysdate").setValue(Date.now());
}

Save, and publish.

3. In your solutions editor, click 'Form Properties' in the entitiy's form you're working with.

4. In Event List, add the new JS resource.

5. In Event Handlers add the function name SetTodaysDateOnLoad 

(Don't add brackets after the function name here)

 

Save and publish and you have the field with today's date accessible in a business rule.

Make sure this field is invisible in your form, or even make it immutable straight after onload and mutable again after updating with the help of a workflow.

Reply
Daniel at VNS responded on 8 Dec 2016 11:33 PM
My Badges
Suggested Answer

Thank you PaulShore - THIS is what i was looking for!

Reply
CRM Trickey responded on 20 Jun 2018 7:44 AM
Suggested Answer

I'd just set the date to be the ModifiedOn using a Set Value Action. Since the Business Rule will be invoked manually this worked in my scenario.

Reply

SBX - Two Col Forum

SBX - Migrated JS