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

Copy multiple variable values into one variable

arundharmabe
Tera Guru

Hello Everyone,

I've a requirement to Copy multiple variable values into one variable. Kindly refer the attached screenshot, in that i would like to copy the "Company", "Available Manufacturers", "Available Locations", etc variable values into "Selected values" variable one by one. Did anyone achieved similar kind of requirement?

 

Regards,

Arun

5 REPLIES 5

SwarnadeepNandy
Mega Sage

Hello @arundharmabe,

To copy multiple variable values into one variable, you can use a Catalog Client Script or a Business Rule to concatenate the values of the source variables and assign them to the target variable. For example, you can use the following script in a Catalog Client Script on the Catalog Item:

 

//Get the values of the source variables 
var company = g_form.getValue(‘company’); 
var manufacturers = g_form.getValue(‘available_manufacturers’); 
var locations = g_form.getValue(‘available_locations’);

//Concatenate the values with a separator 
var selected_values = company + ’ | ’ + manufacturers + ’ | ’ + locations;

//Set the value of the target variable 
g_form.setValue(‘selected_values’, selected_values);

 

 

This script will copy the values of the “Company”, “Available Manufacturers”, and “Available Locations” variables into the “Selected Values” variable, separated by a pipe character (|). You can change the separator to any character you want.

Alternatively, you can use a Business Rule on the Requested Item table (sc_req_item) to copy the variable values after the Catalog Item is submitted. You can use a similar script as above, but replace g_form with current. For example:

 

//Get the values of the source variables 
var company = current.variables.company; 
var manufacturers = current.variables.available_manufacturers; 
var locations = current.variables.available_locations;

//Concatenate the values with a separator 
var selected_values = company + ’ | ’ + manufacturers + ’ | ’ + locations;

//Set the value of the target variable 
current.variables.selected_values = selected_values;​

 

 

This script will run when a new record is inserted in the Requested Item table, and copy the variable values to the target variable.

 

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy

Hi Swarnadeep,

Thanks for the response. For my case BR won't work because it is before submission of the catalog. I tried with the catalog client script but it didn't worked. I am only getting the company value as the output.

 

Below is the code which i tried(getValue only get's the sys_id, so i've used getDisplayBox to get the display value of the reference variable). 

var comp = g_form.getDisplayBox('customer_company').value;
var loc = g_form.getDisplayBox('location').value;

var selected = comp + '|' + loc;

g_form.setValue('selected_values', selected);

 

Regards,

Arun

arundharmabe
Tera Guru

@Ankur Bawiskar Could you please advise on this. 

Abhijit
Tera Expert

worked for me, tested on incident form , for Caller and Assignment group field.

Abhijit_0-1692367248872.png

 

Abhijit_1-1692367320295.png

 

My script screenshot

Abhijit_2-1692367422315.png