- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2023 11:58 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:42 AM
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 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 12:42 AM
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 👍✔️
Anvesh