The CreatorCon Call for Content is officially open! Get started here.

How I translate yes/no to true/false when importing?

vince591
Mega Contributor

I'm importing a csv file which has yes as a value for a checkbox field.   However, SN has True/False.   How do I interpret that?

1 ACCEPTED SOLUTION

No problem. If my answer works for you, please mark it as correct


View solution in original post

9 REPLIES 9

Mussie
ServiceNow Employee
ServiceNow Employee

Hi Jamie,


I have used the following but it isn't working for me:



if (source.u_staff == 'Yes'){  


answer = true;  


else{  


answer = false;  


}


I also tried:


if (source.u_staff == 'Yes'){  


return true;  


else{  


return false;  


}



This is what it looks like:


Screen Shot 2016-03-17 at 3.50.44 PM.png


Any ideas?


Mussie


vince591
Mega Contributor

Mussie,



If you have control over your import data, make the source value 'Yes' and use the original script.


If you don't have control over your import data, then most likely, the source is among the following plausible values;


      all upper case (YES), all lower case (yes), or Proper case like your test (Yes)  



Expand your if test to include the above:



if (source.u_staff == 'Yes' || source.u_staff == 'YES' || source.u_staff == 'yes') {


        answer = true;


else {


        answer = false;


}



I'm sure somebody else out there might have a simpler solution but this should do the trick for now.


I forgot this after the if test and before the end of the function:



        return answer;



})(source);


Mussie
ServiceNow Employee
ServiceNow Employee

Thanks Vincent, that did the trick. I some how forgot to put the below code at the end of the function.



return answer;



Thank you for your help.


Mussie


vince591
Mega Contributor

Mussie,



You're welcome. Glad I could help.



Vincent.