- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 02:30 AM
Hi Community,
I want to remove 'ROCG' keyword from a field which contains values as ROCGTPO12344 etc in this field.
I have written a BR but its throwing some error.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 02:35 AM
use this
var record = new GlideRecord('xyz');
record.query();
while (record.next()) {
record.abc= record.abc.toString().replace('ROCG', '');
record.setWorkflow(false); //Do not run business rules
record.autoSysFields(false); //Do not update system fields
record.update();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 02:42 AM
Hi @Poorva Bhawsar ,
replace method doesn't exist on the Object type
it is available on String type you can you .toString() or .getValue() from the GlideRecord these methods return string type
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 10:05 PM
Hi @Poorva Bhawsar ,
Code looks okay to me, i checked it with running background script and working fine.
var record = new GlideRecord('xyz');
record.query();
while (record.next()) {
// Ensure the field is not null and is a string
if (!gs.nil(record.abc) ) {
record.abc = record.abc.replace('ROCG', ''); // Replace 'ROCG' with an empty string
record.setWorkflow(false); // Skip business rules
record.autoSysFields(false); // Skip system fields updates
record.update();
}
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 10:14 PM
Try below line of code in your code:
record.abc = record.abc.toString()replace(/ROCG/g, '');