business rule to concatenate or combine the first name and last name

Kristin7
Tera Contributor

business rule to concatenate or combine the first name and last name

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Syham,



var first = current.first_name;


var last = current.last_name;


var full = first + ' ' + last;


current.field_name = full;


current.update(); //Don't use current.update if it is before business rule


Change the field column name in above ex


Brian Dailey1
Kilo Sage

Hi Shyam,



That's a pretty general question, if you could elaborate on your needs it would help a bit.   Assuming that you just need a full name available on the user's profile, it doesn't need to be done by business rule.   You can setup a field on [sys_user] to hold a calculated value that concatenates the two.



e.g., Here is the calculation for the 'name' field of the User [sys_user] table



if (!current.first_name.nil() && !current.last_name.nil()) {


current.first_name + " " + current.last_name;


}




You could use something simple like this, or get more complex with your data validation and such.




-Brian


As Brian said, if the particular field going to hold concatenation of first name and last name, why cant you the logic of calculated value.


In this way, you dont have to worry about any Business rule, automatically everytime you update the first name or last name, the full name is auto calculated.



Brian,


In some times, people wont have last name or last name is combined in the first name itself, hence there can be cases where the fields can be empty too.


So simple current.first_name + " " + current.last_name; will work I suppose.


For more information on calculated value set up


System Dictionary - ServiceNow Wiki


Calculated

[Advanced view]


Determines whether the value of the field is calculated from other values. If selected, use the Calculation field to define how the calculation is performed. When sorting or grouping by a calculated field, the sort order is based on the field value from the last time the field was updated, not the last time the field was displayed. Note: In relation to business rules, calculated fields are populated first before any business rule, even a before business rule, is run. Calculated fields are then populated again if necessary after any before business rules run.


Mark if it is helpful