- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 01:41 AM
Hi Community,
I have a BR using which i am removing the spaces from a field. First the data is getting being loaded via scheduled job. Once its loaded an after insert/update BR will work and it will remove the spaces from that field.
Here is the code, i thought it was working fine in background script but now it didnt removed spaces from 2 records.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 01:57 AM
okay got it
then do this and it will replace 1 or more whitespaces
record.abc = record.abc.toString().replace(/\s+/g, '');
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-30-2024 01:57 AM
Hi @Poorva Bhawsar ,
Try using below code.
var record = new GlideRecord('xyz');
record.query();
while (record.next()) {
if (record.abc) { // Ensure the field is not null
var updatedValue = record.abc.toString()
.replace(/ABCD/gi, '') // Case-insensitive removal of 'ABCD'
.replace(/ /g, ''); // Remove all spaces
// Update only if there's a change to prevent redundant saves
if (record.abc.toString() !== updatedValue) {
record.abc = updatedValue;
record.setWorkflow(false); // Skip business rules
record.autoSysFields(false); // Skip system field 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
-------------------------------------------------------------------------