The CreatorCon Call for Content is officially open! Get started here.

concatenating two columns into one

Don11
Mega Expert

Hello,

We have created a database view and was wondering if it's possible to concatenate two columns using a script (see below).

If so can this script can also be applied to a report or automated indicator?

  • var now_GR = new GlideRecord('u_chg_cab_definition_view');

 

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

you can make that field as calculated and store the concatenated value

Use advanced view

Something like this; you can use current object and dot walk to whichever field you wish

(function calculatedFieldValue(current) {

	// Add your code here
	return current.u_cab_meeting + ' ' + current.cab_definition; 

})(current);

find_real_file.png

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

As per my understanding that's not possible

if you wish to do so you will have to create custom field on the table which holds both the fields and concatenate and show that column in database view.

Regards
Ankur

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

Community Alums
Not applicable

Hi Don,

NO!! you cannot concatenate 2 columns. However there is a possibility to do this :

Example:- You have 3 Fields and Need to add all 3 Strings in a single field while any one of out of 3 fields changes.

I Have a field called "Name" and three fields value needs to be added "Name" field

A). First Name

B). Middle Name

C). Last Name

Name = "First Name" + "Middle Name" + "Last Name"

So IN this condition I have 3 OnChange Client script on each field changes (First Name, Middle Name, Last Name). So any one of the fields will be changed, NAME field will be auto concatenated.

********************************************************************

OnChange Client Scrip_1

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var firstname = g_form.getDisplayValue('u_first_name');
var middlename = g_form.getDisplayValue('u_middle_name');
var lastname = g_form.getDisplayValue('u_last_name');

g_form.setValue('u_name', firstname + ' ' + middlename + ' ' + lastname);

}

Note:- Similar you have to write 2 more Client scripts for other field changes.

find_real_file.png

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

 

This is required for database view and not for form.

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

Community Alums
Not applicable

ok..got it