- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 06:59 AM
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();}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 07:45 AM - edited 06-28-2023 07:58 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 07:45 AM - edited 06-28-2023 07:58 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 08:17 AM
This is what I got. I am still lost.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 11:18 AM
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.