- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 11:08 PM
Hi,
Need to comment out particular line in advance script using background script. I have around 2000 different script in the same table and have to comment out or remove the same line that is gs.log how can I do it using background script.
Please advice.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 08:46 PM
Hi,
If it is updating only 1 then I guess script is breaking or giving some exception while iterating; can you update code as below with the try catch block to handle the exception
try{
var gr = new GlideRecord('user_criteria');
gr.addQuery('script', 'CONTAINS', 'gs.log(');
//gr.setLimit(1);
gr.query();
if(gr.next()){
var script = gr.getValue('script');
script = script.replaceAll("gs.log(","//gs.log(");
gr.script = script;
gr.setWorkflow(false);
gr.autoSysFields(false);
gr.update();
}
}
catch(ex){
gs.info('Exception is: ' + ex);
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 06:58 PM
Hi,
Can you check what is the total row count for that query?
var gr = new GlideRecord('user_criteria');
gr.addQuery('script', 'CONTAINS', 'gs.log(');
gr.query();
gs.info('Total Row Count is: ' + gr.getRowCount());
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 07:18 PM
Hi Ankur,
Script: Total Row Count is: 2215
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 08:46 PM
Hi,
If it is updating only 1 then I guess script is breaking or giving some exception while iterating; can you update code as below with the try catch block to handle the exception
try{
var gr = new GlideRecord('user_criteria');
gr.addQuery('script', 'CONTAINS', 'gs.log(');
//gr.setLimit(1);
gr.query();
if(gr.next()){
var script = gr.getValue('script');
script = script.replaceAll("gs.log(","//gs.log(");
gr.script = script;
gr.setWorkflow(false);
gr.autoSysFields(false);
gr.update();
}
}
catch(ex){
gs.info('Exception is: ' + ex);
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2021 05:36 AM
Thank you for marking my response as helpful.
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2019 04:11 AM
Hi,
Can you also mark answer as ✅ correct, 👍 helpful if you were able to achieve the requirement and then close the thread? Thanks in advance
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader