- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 04:44 AM
How to add the duration field(days and hours) to the date time field dynamically and store the result in date time format?
eg.
sla time = 5 days 1 hour
due date = current time(2023-11-28 08:10:50) + sla time
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 05:01 AM
Hello @KARTIK17
You need to write a Script for this :-
var sla = current.sla_time;
var datetime =sla.split(" ");
var date = datetime[0];
var time = datetime[2];
var gdt = new GlideDateTime(gs.nowDateTime());
gdt.addDays(date);
gdt.addSeconds(3600*time);
current.due_date=gdt;
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 05:01 AM
Hello @KARTIK17
You need to write a Script for this :-
var sla = current.sla_time;
var datetime =sla.split(" ");
var date = datetime[0];
var time = datetime[2];
var gdt = new GlideDateTime(gs.nowDateTime());
gdt.addDays(date);
gdt.addSeconds(3600*time);
current.due_date=gdt;
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 06:13 AM - edited 11-29-2023 06:26 AM
hey @Samaksh Wani
var gr new GlideRecord('u_tablename');
gr.addQuery('record=000001111'');
gr.query();
if(gr.next()){
var sla = gr.sla_timer.getDisplayValue(); }
gs.info(sla);
var dateTime = sla.split(' ');
var date = dateTime[0];
var hours = dateTime[2];
var minutes = dateTime[4];
var seconds = dateTime[6];
gs.info(minutes);
var gdt = new GlideDateTime('2023-11-28 08:31:00');
gdt.addDaysLocalTime(date);
gdt.addSeconds (3600*hours);
gdt.addSeconds (60*minutes);
gdt.addSeconds (seconds);
gs.info(gdt);
please find the executions attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 06:29 AM
Hello @KARTIK17
modify your line with mine :-
gdt.seconds(seconds);
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 06:43 AM
Hi @Samaksh Wani , Thanks for quick response.
Even after modifying your line, it throws an error that it is not a function.
Can you please check the attachment, The getDisplayValue function on the sla timer is not displaying seconds even though the second value is there in the duration field.
How to overcome this challenge.?