Add dynamic hrs to current date and time

Ash41
Kilo Sage

Hi Team, 

 

We have a due date on RITM ticket, there is Hours variable with integer type contains dynamic values. based on Hours variable value, we need to add hrs to current date and time then populate in due date.

 

for eg: Due date = Hrs + current date/time.

 

how it can be achieved?

4 REPLIES 4

Community Alums
Not applicable

Hi Shraddha, 

 

I see in link they used static value 13 hrs for addition to date/time field. My concern hrs values will be dynamic here always

Community Alums
Not applicable

@Ash41 --

 

You can get value of the hours field instead of putting static value.

 

 

 

 

Community Alums
Not applicable

@Ash41 --

 

Please write After insert BR 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("sc_req_item");
    gr.addQuery("sys_id", current.sys_id);
    gr.query();
    if (gr.next()) {
        var due_date = String(gr.due_date);
        var gdt = new GlideDateTime(due_date);
        var gtime1 = new GlideTime();
        gtime1.setValue(gs.nowDateTime().slice(11));
        gdt.add(gtime1);
        gr.due_date = gdt.getValue();
        gr.update();
    }

})(current, previous);

 

Thank you!