background script to change field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 03:48 PM
Hi All,
We have a field call url in our project that stores static url +projectno
eg :
https://11111-app.test.com/app/abc/transaction/order.nl?id = <projectno>
https://11111-app.test.com/app/abc/transaction/order.nl?id = <Prj001>
https://11111-app.test.com/app/abc/transaction/order.nl?id = <prj002>
https://11111-app.test.com/app/abc/transaction/order.nl?id = <prj003>
looking for background script to replace - https://11111-app.test.com/app/abc/transaction/order.nl?id = t0
https://123111-app.testing.com/appications/xyz/transaction/order.nl?id =
for records that has - https://11111-app.test.com/app/abc/transaction/order.nl?id = in URL field.
want to do for 1 record first.
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 04:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 05:14 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 05:09 PM - edited 04-29-2024 05:10 PM
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())