Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how can we set the date time field to default current date with 5pm EST

Akshata5
Tera Guru

Hi

When Demand state changes to complete , project record should be created. I am trying this through Business Rule.

When project record is created , Approved End Date field should  default to current date with 5pm EST. 

 

Basically I am looking for the script, how we can set the Approved End Date field to current date with 5pm EST before the project record is inserted.

 

Regards

Akshatha

1 ACCEPTED SOLUTION

J Siva
Kilo Patron
Kilo Patron

Hi @Akshata5 

What's your instances default time zone? If it's EST then you can refer the below script.

 

var date = new GlideDate().getDisplayValue();

var date_str = date + " 17:00:00";

var final_date = new GlideDateTime(date_str);
gs.print(final_date);

 

View solution in original post

4 REPLIES 4

J Siva
Kilo Patron
Kilo Patron

Hi @Akshata5 

What's your instances default time zone? If it's EST then you can refer the below script.

 

var date = new GlideDate().getDisplayValue();

var date_str = date + " 17:00:00";

var final_date = new GlideDateTime(date_str);
gs.print(final_date);

 

Akshata5
Tera Guru

Thank you so much. It worked like a charm.

Glad to hear.

Thanks for accepting the solution.

Ankur Bawiskar
Tera Patron
Tera Patron

@Akshata5 

check my blog

Convert timezone 

use this sample script as well in before insert/update business rule

var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "EST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime);
gs.info('GMT time' + new GlideDateTime());
gs.info("Converted Time to EST: "+gdtConvertedDateTime);
current.setDisplayValue('dateTimeField', gdtConvertedDateTime);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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