Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

background script to change field value

CV1
Tera Contributor
3 REPLIES 3

var tableName = '<table name>';
var oldURL = 'https://11111-app.test.com/app/abc/transaction/order.nl?id';
var newURL = "https://123111-app.testing.com/appications/xyz/transaction/order.nl?id";

var gr = new GlideRecord(tableName);
gr.addEncodedQuery('callLIKE' + oldURL);
gr.query();

if(gr.next()){//update if to while in order to loop through all results

var doc = gr.getDisplayValue('call');
gr.setValue('call', doc.replace(oldURL, newURL));
gr.setWorkflow(false);
gr.update();

}

nataliya_b
Tera Guru

var gr= new GlideRecord(yourtable);

gr.addEncodedQuery("yourfieldCONTAINS11111");

gr.query();

 

if (gr.next())

{

var updatedValue = gr.getValue(yourfield).replace("11111","123111"),replace("test","testing").replace("app","applications").replace("abc","xyz");

gr.setValue(yourfield,updatedValue);

gr.setWorkflow(false);

gr.update();

}

If you happy with results, change if(gr.next()) to while (gr.next())