Number padding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2008 05:28 AM
When we first implemented incident in Service-Now, either "Maximum Digits" wasn't a field in the Number Maintenance module, or we just didn't know enough to set it. Either way, we would like to set it now. Is there a way that we could set max digits now, and apply it to all previously opened incidents?
- Labels:
-
Orchestration (ITOM)
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2008 07:36 AM
It won't change any existing records, you'll need to do that with a script. Something like the following will add a leading zero to the number part of all incidents assuming the prefix is three characters (e.g., "INC"). Depending on how many incidents you have, this could take some time. If just a few tens of thousands, I wouldn't worry. Any more, I'd run it off hours for sure.
You can run arbitrary script by scheduling it in System Definition --> Scheduled Jobs, then just clicking Execute Now on your scheduled script.
addPrefix();
function addPrefix() {
var pre = '';
var num = '';
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
gr.setWorkflow(false); // so no business rules are run
pre = gr.number.toString().substr(0,3); //first 3 chars of original number
num = gr.number.toString().substr(3); //rest of original number
gr.number = pre + '0' + num;
gr.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2008 01:34 PM
Thanks much. That did it, but I did modify your script slightly:
addPrefix();
function addPrefix() {
var x = 0;
var pre = '';
var num = '';
var len = '';
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
gr.setWorkflow(false); // so no business rules are run
pre = gr.number.toString().substr(0,3); //first 3 chars of original number
num = gr.number.toString().substr(3); //rest of original number
len = gr.number.toString().length;
if(pre == 'INC' && len < 11){
for (x = 0; x < (11-len); x++){
num = '0' + num;}
gr.number = pre + num;
gr.update();}
}
}
Do you know of anyway to run this without changing the updated timestamp? I probably can't convince my boss to do this unless I can leave that unchanged... Probably not but I figured I'd ask.