Need to comment out using background script

Heisenberg
Tera Contributor

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.

1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

12 REPLIES 12

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Script: Total Row Count is: 2215

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Heisenberg 

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

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader