re-number old records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2013 12:39 AM
Hi all,
I have a table that I want to update all existing records with an ID number. How can I do that with a script?
any ideas?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2013 02:30 AM
Hello vesta.satari,
you have to query all records in this table and set the number you want. Please refer to the https://wiki.servicenow.com/index.php?title=GlideRecord for quering the database.
// initialize new object of type incident
var gr = new GlideRecord('incident');
gr.query();
var num = 0;
// iterate through the result set
while(gr.next()) {
num++;
gr.setValue('number', 'NEWNUM' + num);
//save
gr.update();
}
Cheers,
Kostya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2013 03:31 AM
Thanks! It is a handy suggestion!
But I did it this way:
var grp = new GlideRecord('sys_user_group');
grp.query();
while(grp.next()) {
if (grp.u_number == '') {
var nm = new NumberManager('sys_user_group');
grp.u_number = nm.getNextObjNumberPadded();
grp.update();
}
gs.print(grp.u_number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2013 06:25 AM
I was tasked to do this once.. way back when I only had a couple months of experience with ServiceNow. That must have been one of the scariest things I've had to do for data manipulation that couldn't be done through update sets. This was the first time I had to change live data in a production environment.
The solution above should work just fine. It's better once you realize incident numbers aren't important in ServiceNow and you can change them to whatever you wand and things will be just fine in the end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2013 01:42 PM
You may wish to have them numbered in the order in which they were created.
before your query, add:
grp.orderBy('sys_created_on');