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

Chuck Tomasi
Tera Patron

I'm not sure about the u_user_brand field, so I'll take it on blind faith.



I also removed the sys_id query. That looks for a specific record. You said "all users".



function addPrefix(){


var gr = new GlideRecord("sys_user");


gr.addQuery('u_user_brand', 'Beta');


gr.query();


while(gr.next())


{


gr.employee_number = 'Beta:' + gr.getValue('employee_number');


gr.update();


}


}


addPrefix();


Thank you


I'm glad it worked. Would you mind marking my response 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.


If you are viewing this discussion from your "inbox", use the "mark as correct" option under actions. If you are viewing it directly from the thread use the Correct Answer link (red with a star).


Thank you


Sorry . I am trying to do that . When i drop down on Actions , it doesn't gives me any actions listed