Concatenate Reference Field and String Field

sarahyelton
Tera Expert

I have a before business rule that populates a string field with the concatenated value of a reference field and a string field; all on the same form/table.  Concatenation works, but I get the sys ID of the reference field value.  I have tried a bunch of script examples, but this is the "base".  BusApp is the reference field.  Please help.  🐵

 

Condition:  current.u_business_application.changes() || current.u_profile.changes() || current.operation() == 'insert'

Script:

//Get the values of your two objects
var curBusApp = current.getValue('u_business_application');
var curProfile = current.getValue('u_profile');

//Set the display Value
current.setDisplayValue('u_name', curBusApp + '-' + curProfile);
current.update();

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sarah,

since it is a reference field it will give sys_id if you use getValue; use getDisplayValue() to get the display value

//Get the values of your two objects
var curBusApp = current.getDisplayValue('u_business_application');
var curProfile = current.getValue('u_profile');

//Set the display Value
current.setDisplayValue('u_name', curBusApp + '-' + curProfile);
current.update();

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sarah,

since it is a reference field it will give sys_id if you use getValue; use getDisplayValue() to get the display value

//Get the values of your two objects
var curBusApp = current.getDisplayValue('u_business_application');
var curProfile = current.getValue('u_profile');

//Set the display Value
current.setDisplayValue('u_name', curBusApp + '-' + curProfile);
current.update();

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I KNEW it would be a simple fix.  Thank you!!!!

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


There can be two ways one which Ankur said and other which i think:

 

//Get the values of your two objects
var curBusApp = current.u_business_application.name; //This name is a name field on that reference table i.e. where business application is referring two. It can be u_name or name or may be somethere field also you can use if you want.
var curProfile = current.getValue('u_profile');

//Set the display Value
current.setDisplayValue('u_name', curBusApp + '-' + curProfile);
current.update();

 

Thanks,
Ashutosh