Update method is not working in the Fix script to update the historical records

Siddhesh Wani1
Tera Guru

I created one fix script(global scope) to update resolve time(field type - integer) field in the Universal request.
The update function is not working and it's happening only for the Universal request same functionality is used for the general request and it's working fine there. 

 

Fix script code - 

resolvetime();
function resolvetime()

{
var sw = new GlideRecord('universal_request');
sw.addQuery('sys_id', ' sys_id of the universal request '); // passing sys_id of specific record to check 
sw.query();
if (sw.next()) {
        var opened = sw.opened_at.getDisplayValue(); // UR open time 
        var resolve = sw.u_resolved.getDisplayValue(); // UR resolve time 
        var date = gs.dateDiff(opened, resolve, true);   // diff is in the seconds 
        gs.info("@#$ datediff " + date);
        sw.u_resolved_time = date;
        gs.info("@#$ resolve time value "+ sw.u_resolved_time);
        sw.update();  // this function is not working 
}
}

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

When you run this Fix Script, obviously it seems like you are not seeing the records updated, but does it show the correct info logs?  Is there any indication on the progress worker for the fix script or the runtime window in foreground that the update did not execute correctly?  Is there anything in the system logs at this same time that gives any insight?  Are you able to update the same field on this record manually by viewing the record?  There may be a data policy, ACL, or Business Rule preventing the update. To that end, try adding a line before the update to prevent any business rules from running before/after the record is updated:

sw.setWorkflow(false);

 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

When you run this Fix Script, obviously it seems like you are not seeing the records updated, but does it show the correct info logs?  Is there any indication on the progress worker for the fix script or the runtime window in foreground that the update did not execute correctly?  Is there anything in the system logs at this same time that gives any insight?  Are you able to update the same field on this record manually by viewing the record?  There may be a data policy, ACL, or Business Rule preventing the update. To that end, try adding a line before the update to prevent any business rules from running before/after the record is updated:

sw.setWorkflow(false);