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 Pradeep ,



Just curious to know



What is the benefit of using the gr.getValue('employee_number') instead of   gr.employee_number ??




employee_number is a GlideElement object. When you copy and object, you get everything that object has. In most cases, this isn't a problem. If you are inside a while loop, it can be an issue (particularly for sys_ids.)



Using getValue() can remove many of these problems. I just started using it as a matter of habit to avoid such issues.


Thanks tomasi


dan.bruhn Sree is still having issues (even with a different browser.) Can you assist? I think I had this on the first comment.


Hi Chuck,



We thought this was related to a caching issue.   After we cleared the cache I was hoping Sree would see the correct answer button.   It doesn't seem to be the case.   I'll need to forward this thread to them so it can be added to their case.  



Thanks,