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 11:34 AM
Hi Pradeep ,
Just curious to know
What is the benefit of using the gr.getValue('employee_number') instead of gr.employee_number ??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 11:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 11:42 AM
Thanks tomasi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 11:44 AM
dan.bruhn Sree is still having issues (even with a different browser.) Can you assist? I think I had this on the first comment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 01:47 PM
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,