Background script to update the serial number for 225 Linux servers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2026 07:47 PM
Hi Everyone
can someone help me to get the background script to update the serial number filed for 225 Linux servers
Thanks
Ruthirakotti A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2026 07:55 PM
try this :
var count = 0;
var grLinux = new GlideRecord('cmdb_ci_linux_server');
grLinux.addEncodedQuery('install_status=1^manufacturer=HardwareManufacturer^serial_number='); //Replace the encoded query below with the exact filter for your 225 servers
grLinux.setLimit(5); // Change to gr.setLimit(225) after validating your test run
grLinux.query();
while(grLinux.next()) {
grLinux.serial_number = 'YOUR_NEW_SERIAL_NUMBER'; //Set your serial no
grLinux.setWorkflow(false);
grLinux.update();
count++;
}
gs.info('Successfully updated ' + count + ' Linux server records.');
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2026 08:09 PM
so what script did you start and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2026 08:59 PM
Hi Ruthirakotti,
Quick question first, since it changes the script: do you want all 225 servers to get the same serial number, or 225 distinct serials?
Before either approach, confirm you're actually targeting 225 records (a plain query hits the whole table, which may be more or fewer than 225). Run this on its own first:
var gr = new GlideRecord('cmdb_ci_linux_server');
gr.query();
gs.info('Records that will be updated: ' + gr.getRowCount());
If you need a subset, add an encoded query (e.g. gr.addEncodedQuery('...')) to scope it down.
Same serial for all:
var gr = new GlideRecord('cmdb_ci_linux_server');
gr.query();
var count = 0;
while (gr.next()) {
gr.serial_number = 'NEW_SERIAL_HERE';
gr.update();
count++;
}
gs.info('Updated ' + count + ' records.');
Distinct serials: this depends on where the values come from. If they follow a pattern, a formula works:
var gr = new GlideRecord('cmdb_ci_linux_server');
gr.query();
var count = 0;
while (gr.next()) {
gr.serial_number = 'SN-' + gr.getValue('name'); // pattern only
gr.update();
count++;
}
gs.info('Updated ' + count + ' records.');
But if these are 225 real serials from a spreadsheet, a background script isn't the best tool — an Import Set + Transform Map (coalescing on name or serial) is cleaner, repeatable, and gives you an audit trail. If you'd rather stay in script, you could load a name→serial mapping object and look each one up in the loop.
please Mark helpful, if my reply adds any value