How to separate the data from one column into two different fields?

aakankshapl
Tera Expert

Hi,

I am loading data using transform map and in that their is 1 column in excel sheet called Location. 

In that Location column data is written as X,Y(City, State) so while loading the data I want to separate the X in City field and Y in State field. I am not getting how to achieve that. Please help me to understand it. It will be a great help for me.

Thank you

aakankshapl_0-1709706893789.png

 

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, you could use 2 x scripted field maps and string methods to separate out the 'answer' for each target field.
Or you could use a beforeTransform script to deliver same results.
For a field map script, something like this should work (untested).

(edited as script should return a result, not assign it to answer)

 

var tempSource = source.fieldName.split(',');
return tempSource[0].toString();

 

 

Sumanth16
Kilo Patron

Hi @aakankshapl ,

 

Please create the script like below:

 

Create field mapping with the following code
answer = (function transformEntry(source) {
var imei = source.u_city.toString().split(',')[0]);
return imei; //Will return city
}

answer = (function transformEntry(source) {
var imei = source.u_city.toString().split(',')[1]);
return imei; //Will return state
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda