The CreatorCon Call for Content is officially open! Get started here.

autopopulate date\time field

Shir Sharvit
Tera Contributor

hey.

 

I have a date\time field called expected_start
and another date of duration time type called u_duration_time
- I want to populate the u_expected_date field which is a date\time field
add u_duration_time to expected_start and populate u_expected_date.

 

I created a business rule but this doesn't fit my hours well (adds 2 more hours).

 

ShirSharvit_0-1734610326196.jpeg

 

I would appreciate some help please

 

 

4 REPLIES 4

Najmuddin Mohd
Mega Sage

Hi @Shir Sharvit ,
You can check the below script for the following example,

NajmuddinMohd_0-1734612636043.png

 


I have added One day, two hours in the duration.

var gr = new GlideRecord('incident'); // You can change this to your desired table
if (gr.get('sys_id', '192bb84f08baf410f8771cb78588807e')) { // Replace with the actual Sys ID of the record

    var date_time = new GlideDateTime(gr.u_custom_date_time.getDisplayValue());
    gs.info(date_time.getValue());
    var duration = gr.u_custom_duration.dateNumericValue();
    date_time.add(duration);
    gs.info(date_time.getValue());
}

 

Output:

 

*** Script: 2024-12-20 04:30:17
*** Script: 2024-12-21 06:30:17

 

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

Juhi Poddar
Kilo Patron
Kilo Patron

Hello @Shir Sharvit 

You can refer the following post: How to add data of two time types

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to find the solution easily and supports the community!"

 

Thank You
Juhi Poddar

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Shir Sharvit 

your BR should be before insert/update

Script is correct

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

@Shir Sharvit 

Hope you are doing good.

Did my reply answer your question?

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