- 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-21-2019 11:33 PM
Hi Heisenbery,
Can you explain in detail?
Are you saying you are having many background scrips with the line of code as gs.log() and you would like to comment that line of code from every background script which has that?
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-21-2019 11:38 PM
Hi Ankur,
I have a many user criteria with script in that by mistake I have added gs.log in it which needs to be commented out, can I do it through background script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 11:55 PM
Hi Heisenbery,
Somewhat trickier to handle this; since it is a script field and you will have to search for the text gs.log( in that complete string and replace the text with //gs.log(
try this script below and it would search user_criteria table where script contains gs.log and will replace with //gs.log :
Try first with setLimit(1) and check whether it got changed and then comment out that line
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();
}
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 09:17 AM
Hi Ankur,
It updates only 1 record, even after removing setlimit, can you help what changes could be made on this.