autopopulate date\time field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 04:13 AM - edited 12-19-2024 04:14 AM
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).
I would appreciate some help please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 04:51 AM
Hi @Shir Sharvit ,
You can check the below script for the following example,
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 05:14 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 05:21 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 10:26 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader