How to set a default value for a date/time field

Jerome MAISETTI
Mega Guru

Hello All
I have a date/time field which I would like to be set to three days from now as default when a ticket goes into Pending Customer.
How can I achieve this ? Can I put  a default value in the dictionary field or should I use a client script ?
Thanks

1 ACCEPTED SOLUTION

Mahendra RC
Mega Sage

Hello @Jerome MAISETTI 

You can use the below script in Before Update BR:

Condition: State is on Hold AND On hold reason changes to Pending Customer

Before update BR Script:

var nowGDT = new GlideDateTime();
nowGDT.addDays(3);
var nowDateNumericValue = nowGDT.getNumericValue();
current.<your_date_time_field_name>.setDateNumericValue(nowDateNumericValue);

 

View solution in original post

6 REPLIES 6

Alikutty A
Tera Sage

@Jerome MAISETTI  The right way is to setup an onbefore business rule based on your condition as States changes to Pending Customer and write the GlideDateTime script in it to set your field.

Mahendra RC
Mega Sage

Hello @Jerome MAISETTI 

You can use the below script in Before Update BR:

Condition: State is on Hold AND On hold reason changes to Pending Customer

Before update BR Script:

var nowGDT = new GlideDateTime();
nowGDT.addDays(3);
var nowDateNumericValue = nowGDT.getNumericValue();
current.<your_date_time_field_name>.setDateNumericValue(nowDateNumericValue);

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You cannot use default value in dictionary. Default value in dictionary is meant to be used only once when new record is getting created.

you can use BR approach shared by Mahendra.

Can you share what script did you try so far and what's not working?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 

 

I'm trying to set a future date as the default value in a field, but when I use javascript&colon;now(); it populates the present date instead. How do I do it correctly?