Query and Update using a script

Heather White
Mega Guru

 

Hi Community,

I would like to create a  script that will query any records where resolved_at and resolved_by are empty, and set them to a specific value. 

I had assistance creating the following script to update records on my user table.

How do I alter the script to work on the incident table?

var recUser = new GlideRecord('sys_user');
recUser.addEncodedQuery('company=a828cffe993928006d095f1cc569621f^sys_class_name!=sys_user^ORsys_class_name=NULL');
recUser.query();
gs.info(recUser.getRowCount());
while(recUser.next()){
recUser.sys_class_name = 'sys_user';
recUser.update();
}

Thanks,

Heather

 

1 ACCEPTED SOLUTION

You want the resolved_at to be 24 hours after the incident was closed? Wouldn't that be a bit weird? To have the ticket resolved after it was closed?

You can do it this way but check out how to do it 24 hours before as well:

//to set resolved after closed:
var gdt = new GlideDateTime(recUser.getValue('closed_at'));
gdt.addDays(1);
recUser.resolved_at = gdt;
recUser.resolved_by = ''; // Pass the sys_id of the user
recUser.update();

//to set resolved before closed:
var gdt = new GlideDateTime(recUser.getValue('closed_at'));
gdt.addDays(-1);
recUser.resolved_at = gdt;
recUser.resolved_by = ''; // Pass the sys_id of the user
recUser.update();

View solution in original post

10 REPLIES 10

Heather White
Mega Guru

Thanks David!