Number Maintainance

Gaurav69
Tera Contributor

Hii, I have created a number maintenance on user (sys_user) table. When I create new a user record the number is working fine but its not showing numbers in already existing records. how can I show the number in already existing records?

Thanks in Advance. 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Gaurav69 You need to use a fix script to populate numbers on the existing records use 

getNextObjNumberPadded();

 

to generate number for your existing records in a fix script.

 

Please refer to this link for more information https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/field-admini...

 

Hope this helps.

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Gaurav69 You need to use a fix script to populate numbers on the existing records use 

getNextObjNumberPadded();

 

to generate number for your existing records in a fix script.

 

Please refer to this link for more information https://docs.servicenow.com/bundle/washingtondc-platform-administration/page/administer/field-admini...

 

Hope this helps.

Hii Sandeep, Thank you so much for the solution. Can you help me with the Script also if possible.

Thanks in advance.

@Gaurav69 Here is the sample script for you.

var glideUser = new GlideRecord('sys_user');
glideUser.addEncodedQuery('number=NULL'); //Replace number with the name of your number field
glideUser.query();
while (glideUser.next()) {
    var numMgr = new NumberManager('sys_user');
    var newNum = numMgr.getNextObjNumberPadded();
    glideUser.setValue('number',newNum);//Replace number with the name of your number field
    glideUser.update();
}

Caution: Please do not run this script in production directly. Run this script in a sandbox/non-prod instance with a single record first (use if instead of while). Verify, if it works well then proceed with the other instances.

 

Please mark the response helpful and accepted solution if it manages to address your question.