- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 11:18 AM
Hi Team,
Greetings of the day.
We have a choice field on user table called 'Employee Type', If the employee type is vendor, need to automatically add prefix ''V-'' before the first name if there is no "V-" before it.
Please help to achieve this.
Thanks a lot.
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 11:25 AM
You can try running Background script for existing record and BR for new record:
var usr = new GlideRecord('sys_user');
usr.addQuery('employee_type','vendor');
usr.query();
while(usr.next())
{
if(usr.indexOf('V-')
{
var fName = 'V-' + usr.first_name;
usr.first_name = fName;
usr.update();
}
}
For Business Rule, no need to GlideRecord User record, instead can use current instead of usr.
Please mark this as correct answer if it resolved, or mark this helpful if this help you to reach towards solution.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 11:25 AM
You can try running Background script for existing record and BR for new record:
var usr = new GlideRecord('sys_user');
usr.addQuery('employee_type','vendor');
usr.query();
while(usr.next())
{
if(usr.indexOf('V-')
{
var fName = 'V-' + usr.first_name;
usr.first_name = fName;
usr.update();
}
}
For Business Rule, no need to GlideRecord User record, instead can use current instead of usr.
Please mark this as correct answer if it resolved, or mark this helpful if this help you to reach towards solution.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 02:30 PM
That works!, Thanks a lot