background script to update user information

Kristina2
Tera Contributor

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();

24 REPLIES 24

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,


absolutely, nO ISSUES . Please go forward .


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

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


Finally , it worked ,. Thank You


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