- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 09:00 AM
Hello Experts,
I have created auto numbering for existing software model table. The issue is we have few old records for which we need numbering as well but it works only for newly created records. Is there a way to generate numbering for existing records as well. Thank you in advance.
Thanks & Regards,
Jag.
Solved! Go to Solution.
- Labels:
-
Enterprise Asset Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 11:49 AM
Sorry change line 6 to gr.u_number so...
var gr = new GlideRecord("cmdb_software_product_model");
gr.orderBy('sys_created_on');
gr.query();
while (gr.next()) {
var nm = new NumberManager('cmdb_software_product_model');
gr.u_number = nm.getNextObjNumberPadded();
gr.autoSysFields(false); // Do not update sys_updated_on, sys_updated_by, and sys_mod_count
gr.setWorkflow(false); // Do not run any other business rules
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 10:40 AM
Please try this out, I am assuming in your number maintainance you have selected 7 digits and starting number as 1000
var prefix = "SW";
var zero = "000";
var counter = 1000;
var gr = new GlideRecord('cmdb_software_product_model');
gr.query();
while(gr.next() && counter<1825){
counter += 1;
var num = counter.toString();
gr.u_number = prefix+zero+num;
gr.update();
}
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 10:48 AM
Yes that's true. I kept the starting number as 1000.
I tried the above script but it din't work now as well. The number dint get populated.
Thanks,
Jag.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 10:50 AM
Thats wierd It worked on my developer instance.
Are you working on a developer instance?
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 10:53 AM
Yes, I am working on our dev instance. Do we need to remove any default value in Number at dictionary level?
Thanks,
Jag.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2017 11:04 AM
No change is required on the number dictionary. Can you show me a screenshot of your number maintenance record?
Also see what log this code prints when you execute it
var prefix = "SW";
var zero = "000";
var counter = 1000;
var gr = new GlideRecord('cmdb_software_product_model');
gr.query();
while(gr.next() && counter<1825){
counter += 1;
var num = counter.toString();
gs.print(prefix+zero+num);
gr.u_number = prefix+zero+num;
gr.update();
}
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response