background script to update user information
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 08:59 AM
Table : sys_user
I am trying to run a piece of code , its not working , i would like to get people inputs ,
We need a background script to update the Employee Number for all people with a User Brand = "Beta""
to add "Beta:" as a prefix to the existing Employee Number.
So it should display as " Beta: 25467".
Code :
function addPrefix(){
var gr = new GlideRecord("sys_user");
gr.addQuery('sys_id',"bac617ddd56c8104583a92146e8f872a");
gr.addQuery('u_user_brand', 'Beta');
gr.query();
while(gr.next())
{
gr.user_brand = gr.employee_number.replace('Beta:');
gr.update();
}
}
addPrefix();
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 02:01 PM
Hi Sree,
Would it be alright if someone from our technical team reaches out to you? It would be very helpful in our efforts to troubleshoot the issue.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2016 01:45 PM
absolutely, nO ISSUES . Please go forward .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 09:05 AM
Here you go.
addPrefix();
function addPrefix(){
var gr = new GlideRecord("sys_user");
gr.addQuery('u_user_brand', 'Beta'); //I am asusming this is a string field
gr.query();
while(gr.next())
{
gr.employee_number = 'Beta:' + gr.getValue('employee_number');
gr.setWorkflow(false); //turn off notifcations.
gr.update();
}
}
Background Scripts — ServiceNow Elite
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 09:12 AM
Finally , it worked ,. Thank You

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 09:16 AM
Great Sree
I hope we answered your question. If so, please mark it as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list. Thank you