How to concatenate 2 source fields into 1 target field on a transform

Basha4
Tera Expert

In Field Map, in the source table, I have two fields and I want to add two fields and the result comes in the target table 

ex: First name & Last Name, both added and results may come in the target table

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hello,

You can either use a field map on one source field (but then check the script box) or use the transform map script (script field right in the center of the transform map itself) and do something like:

//for field map
var string = source.u_first_name.toString() + " " + source.u_last_name.toString();
return string;

//for transform map
var string = source.u_first_name.toString() + " " + source.u_last_name.toString();
target.field_name = string;

The above are examples, please take it from here!

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Abhijit4
Mega Sage

You can create mapping for one of the source field (lets say first name field) with target field. In field map script, you can concatenate first name and second name field and return that value which will get automatically in target table.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Allen Andreas
Administrator
Administrator

Hello,

You can either use a field map on one source field (but then check the script box) or use the transform map script (script field right in the center of the transform map itself) and do something like:

//for field map
var string = source.u_first_name.toString() + " " + source.u_last_name.toString();
return string;

//for transform map
var string = source.u_first_name.toString() + " " + source.u_last_name.toString();
target.field_name = string;

The above are examples, please take it from here!

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Kalyani Jangam1
Mega Sage
Mega Sage

In transform script, you can add below logic

(function transformRow(source, target, map, log, isUpdate) {

    target.user_name=source.u_firstname + source.u_lastname;// field name as per your condition

})(source, target, map, log, action==="update");

Pavankumar_1
Mega Patron

Hi,

refer below screen shot on source script you can add the n number of fields based on your requirement.

use source method to get source value.

Example: 1

var fullname = source.u_first_name.toString() + '-' + source.u_last_name.toString();

return (fullname);

 

Example:2 Source Script: It will return as object. try below 

answer = (function transformEntry(source) {

    var data = {
        'Number': source.u_number + '',
        'Order ID': source.u_order_id + '',
        'SAP Status Code': source.u_sap_status_code + '',  
    };
    return (JSON.stringify(data));
    //return data; // return the value to be put into the target field

})(source);

 

find_real_file.png

Result:

{"Number":"CS00944591","Order ID":"5000090","SAP Status Code":"201"}

 

Thanks,

Pavankumar

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar