Need to add Prefix before user's first name

Arjun4
Tera Contributor

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. 

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage
Mega Sage

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.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

2 REPLIES 2

AnubhavRitolia
Mega Sage
Mega Sage

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.

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

That works!, Thanks a lot