Issues Transforming String to Boolean on Transform Map

Erik Nelson
Kilo Sage

Hello all,

 

I'm having some trouble getting string TRUE and FALSE fields mapping to their Boolean counterparts as part of their transform map. They won't map directly, so I've been trying various script versions (both as a before as well as directly on the field map) including things like:

answer = (function transformEntry(source) {

if (source.u_released.toLowerCase() == "yes") {

return true;

if (source.u_released.toLowerCase() == "no") {

return false;

})(source);

 

and 

 

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

 

    answer = true;



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

 

    answer = false;

 

 

The only thing that appears to happen is the incoming .csv has the values in all caps, but it's being brought in as "True" and "False". Any thoughts, ideas, assistance from the community?

 

Thank you!

2 REPLIES 2

Saloni Suthar
Mega Sage
Mega Sage

Please check below to see if it works:

https://www.servicenow.com/community/developer-forum/transform-script-for-true-false-field-in-target...


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

Luiz Lucena
Mega Sage

Hi @Erik Nelson 

 

Have you tried toUpperCase instead of toLowerCase?

Also, on your script, you are passing the function to the variable answer.

But is not returning the answer itself.