Script not working in PROD

Dallas Fanchier
Tera Expert

I wrote a script but it stopped working in PROD.  I tested the same script in lower environments and it was working.  I haven't had any major updates or upgrades in PROD.  I am not sure what broke.  The script runs and updates the record but doesn't set the install date like I have wrote in the script.  My logic behind script is update installed date field with the last updated on field with the filter being not updated on today and installed is not empty.  I am not sure where to look for issues.

 

var gr = new GlideRecord("cmdb_ci_patches");

gr.addEncodedQuery ("install_dateISEMPTY^sys_updated_onNOTONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");

gr.query(); while(gr.next()){

gr.install_date = gr.sys_updated_on;

gr.update();}

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hi Dallas,

 

Your script works for me, some debug to help determine what is wrong:

 

 

var gr = new GlideRecord("cmdb_ci_patches");

gr.addEncodedQuery("install_dateISEMPTY^sys_updated_onNOTONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");

gr.query();
gs.info("Found " + gr.getRowCount() + " records to process.");
while(gr.next()){
gr.install_date = gr.sys_updated_on;
gs.info("Updating install_date for " + gr.name);
var rc = gr.update();
gs.info("rc = " + rc);
}

 

 

'rc' should contain the sys_id of the record being updated.  And the use of 'gr' for GlideRecord() can fail as some platform code uses that variable and can 'clobber' that value in your code.  Try using 'ciPatch' in place of 'gr'.

 

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

on the use of 'gr' in scripts.

View solution in original post

3 REPLIES 3

Bert_c1
Kilo Patron

Hi Dallas,

 

Your script works for me, some debug to help determine what is wrong:

 

 

var gr = new GlideRecord("cmdb_ci_patches");

gr.addEncodedQuery("install_dateISEMPTY^sys_updated_onNOTONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");

gr.query();
gs.info("Found " + gr.getRowCount() + " records to process.");
while(gr.next()){
gr.install_date = gr.sys_updated_on;
gs.info("Updating install_date for " + gr.name);
var rc = gr.update();
gs.info("rc = " + rc);
}

 

 

'rc' should contain the sys_id of the record being updated.  And the use of 'gr' for GlideRecord() can fail as some platform code uses that variable and can 'clobber' that value in your code.  Try using 'ciPatch' in place of 'gr'.

 

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

on the use of 'gr' in scripts.

This is what I got.  I am still lost.

DallasFanchier_0-1687965441752.png

 

Bert_c1
Kilo Patron

Hello Daniel,

 

I still see "gr" in your script, but it looks like your record was updated. Can you update the install_date field from a list view of 'cmdb_ci_patches'? Please read the Knowledge Article I posted. However, there may be Business rules, Data Policies, etc. that are in play in your instance.  Maybe it is time to clone over a sub-prod instance to test in.