Transform Script combine multiple source fields into one target field

brown9394
Tera Expert

Hello Experts, 

I need to take 3 different Source fields and combine them into 1 target field. How can I do this with a transform script? 

For example:

Source fields -

field_a = 'These are my notes from a' 

field_b = 'and from b'

field_c = 'and from c'

And I want to combine it with a ', ' and space like this example output below in 1 Target table field -

field_a = 'These are my notes from a, and from b, and from c'

Thanks in advance! 

1 ACCEPTED SOLUTION

vkachineni
Kilo Sage
Kilo Sage

var combined = [];

if(source.u_field_a != '')
{
combined.push(source.u_field_a);
}
if(source.u_field_b != '')
{
combined.push(source.u_field_b);
}
if(source.u_field_c != '')
{
combined.push(source.u_field_c);
}

target.field_name = combined.join(", ");

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

5 REPLIES 5

Alikutty A
Tera Sage

Hi,

You can write an onbefore transfrom map script with the following line in it.

 

target.field_name = source.u_field_a + ', '+ souce.u_field_b + ', ' +source.ufield_c;

Replace your field names appropriately

Thanks!

Hi, 

This worked, however, seeing an issue when not all 3 source fields have values, the empty field is copying with a target out put of 'This are my notes from a, and from b, ,'

Is there a way to skip over the empty fields from source, so it doesn't write with a ' ,' in the target field? 

 

Try the script provided by vkachineni

 

vkachineni
Kilo Sage
Kilo Sage

var combined = [];

if(source.u_field_a != '')
{
combined.push(source.u_field_a);
}
if(source.u_field_b != '')
{
combined.push(source.u_field_b);
}
if(source.u_field_c != '')
{
combined.push(source.u_field_c);
}

target.field_name = combined.join(", ");

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022