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.

Fix script to write Closed date is created date plus 1 minute in incident table

Servicenow de11
Tera Contributor

Hello,

 

I have a reqirement that is in the incident table closed date field is equal to created date field + 1 minute.I need to write fix script for this.

 

Can anyone suggest the script to achieve this.

 

Thanks in advance

 

 

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @Servicenow de11 

You can refer this sample script. I'm updating just for one incident by it's sys_id, you can use the same logic just by changing the query.

 

var gr = new GlideRecord("incident");
gr.addQuery("sys_id", "c2a902bc97cf39104234fa56f053af26"); // Get Incident by it's SYS_ID
gr.query();

while(gr._next()){
    var created_at = gr.sys_created_on; // Get created time
    var gdt = new GlideDateTime(created_at); // Create GlideDateTime object from created time
    gdt.addSeconds(60); // Add One minute to the created time
    gr.closed_at = gdt.getDisplayValue(); // Set closed_at time with created + 1 minute
    gr.setValue('state', '7'); // Set the state to closed
    gr.update();
}

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

View solution in original post

1 REPLY 1

AnveshKumar M
Tera Sage
Tera Sage

Hi @Servicenow de11 

You can refer this sample script. I'm updating just for one incident by it's sys_id, you can use the same logic just by changing the query.

 

var gr = new GlideRecord("incident");
gr.addQuery("sys_id", "c2a902bc97cf39104234fa56f053af26"); // Get Incident by it's SYS_ID
gr.query();

while(gr._next()){
    var created_at = gr.sys_created_on; // Get created time
    var gdt = new GlideDateTime(created_at); // Create GlideDateTime object from created time
    gdt.addSeconds(60); // Add One minute to the created time
    gr.closed_at = gdt.getDisplayValue(); // Set closed_at time with created + 1 minute
    gr.setValue('state', '7'); // Set the state to closed
    gr.update();
}

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh