Loading data into True/False data types

sigmachiuta
Kilo Guru

I have a data set with True/False data types.   When i export the data from the other system the values are either t or f . not True / False or 1/0.   When I import the data SNow does not recognize that i na True/False field t is true and f is false.   Is there any way to import the values as-is and have the transform understand that if I am entering into a true/false data type that t is true and f is false.   I dont want to change all the values in the import because there are a lot of fields and hundreds of thousnads of rows.

1 ACCEPTED SOLUTION

A before script would definitely work, however I would suggest editing the field map with a script because that way you have all the logic together at the field map level.   Open your existing field map for the true false field and then check the Use source script box and paste in the following:



if (source.field == "t" || source.field == "1") {


    answer = true;



if (source.field == "f" || source.field == "0") {


    answer = false;



These scripts need to have answer="ANSWER", but otherwise they are like any other scripts.


View solution in original post

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

Use data source + transform map. Add a onbefore transform script and use something like this



if(source.field == 't')


{


target.field = true;


}


else


{


target.field = false;


}


A before script would definitely work, however I would suggest editing the field map with a script because that way you have all the logic together at the field map level.   Open your existing field map for the true false field and then check the Use source script box and paste in the following:



if (source.field == "t" || source.field == "1") {


    answer = true;



if (source.field == "f" || source.field == "0") {


    answer = false;



These scripts need to have answer="ANSWER", but otherwise they are like any other scripts.


Michael,


This did work, although I have about 45 T/F fields, this would need to be placed inside each one, and every transform map (i have a few other tables to load with boolean data in the same format)?   Is there a quicker way?


Unfortunately no.   As Kalai suggests, tou can either do this with a script in the transform map, before script, or field map script.   But each requires you to specify the source field so you are repeating this X times.