A bool value keeps showing up as undefined.

Jacob Crowe
Kilo Contributor

I'm trying to write a script that uses if statements to determine an action depending on the value of a bool. If true it does one thing, if false another. I can see in the XML that the field has a true or false value, but when I try to display that value it's just showing it as undefined. Any help would be appreciated. 

1 ACCEPTED SOLUTION

This is very generic statement with no specific details:

Issues with your script is you are getting gliderecord reference in gr variable but you are using thresholdsGR object in next line which is incorrect.

You have to keep using gr in subsequent queries

But you can try something as below for your script:

var gr = new GlideRecord("table_name");
    gr.addQuery("query");
    gr.query();

if(gr.next()){
    var boolValue = gr.specific_field;
    gs.addInfoMessage("boolValue: " + boolValue);

}

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

View solution in original post

5 REPLIES 5

For boolean it is a special case, if you want to use getValue, you will need to type cast it into boolean as below:

var boolValue = Boolean(gr.getValue("field_name")); // will return true or false

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar