Issue with Scheduled Job not updating Records

Wendy Peterson
Giga Guru

I have some scheduled jobs that run to update a record and send notification - for some reason it's not updating the record when it runs. Any ideas? It's supposed to update the 'u_email_sent' to that option below but it does not. TIA

2023-06-28_9-40-54.jpg

var gr = new GlideRecord('u_security_exceptions');
gr.addQuery('u_expiration_dateRELATIVELT@month@ahead@3^u_remove_expiration_dateISEMPTY');       
 //Looks for Expiration Date 90 days and Extended Expiration Date is Empty and Email is not 90 Days or is Empty 
   gr.query();
   while (gr.next()){
      gs.eventQueue("exception90.Notifyuser", gr, gr.u_user, gr.u_user.manager);
      gs.log('Expiration Date: ' + gr.u_expiration_date + " User " + gr.u_user);
      gr.u_email_sent = '90 day';//Updates value to 90 days
      gr.update();
   }

 

1 REPLY 1

Bert_c1
Kilo Patron

Hi Wendy,

 

Do you see the log message in Script Log Statements?  Also, the use of 'gr' for GlideRecord can lead to problems as some platform code uses the variable and can "clobber" your variable in the script. Try using 'uSecExc' in place of 'gr'.  Also try 

 

      gs.log('Expiration Date: ' + gr.u_expiration_date + " User " + gr.u_user);
      gr.u_email_sent = '90 day';//Updates value to 90 days
      var rc = gr.update();   // save value of update
      gs.log("Result code for update() = " + rc);

 

'rc' should be the sys_id of the record being updated, if null, the update is not working.

 

See: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0713029

on the use of 'gr' in scripts.