Why can't I get the Value of my True/False field

Stacy1
Mega Guru

I have a true/false field.  I need to see the value so I can do an If script when it is true.

If I do:  var ip = g_form.getValue('u_ip'); 

The alert is blank.

If I do  var ip = g_form.getBoolenValue('u_ip');

The alert returns false regardless of it being true or false.

I can't do display value because that gives me the Case Number.

Any magic I am missing.  

Thanks,

Stacy

1 ACCEPTED SOLUTION

Hi, syntax looks ok and it works correctly for me if I paste to my instance (after updating the reference field).
Is you field visible on your form?
Is the script 'Active' ?
Is script in correct scope?
If are you domain seperated, is domain correct?
Do you have the correct table selected for the script?

View solution in original post

9 REPLIES 9

Zach Koch
Giga Sage

This link may help you. Sometimes with ServiceNow the string of true/false can be returned instead of the boolean value

https://community.servicenow.com/community?id=community_question&sys_id=8ef44b2ddbd8dbc01dcaf3231f96...

Prasad Dhumal
Mega Sage

is your Boolean field is present on the form section??

Tony Chatfield1
Kilo Patron

Hi, var ip = g_form.getValue('u_ip'); would appear to be correct sytax,
and an alert shoudl be failry striaght forward.

https://developer.servicenow.com/dev.do#!/reference/api/quebec/client/c_GlideFormAPI#r_GlideFormGetValue_String?navFilter=getvalue

From the client\form side true\false will be 'text' not actually bool, so if you are validating a value you would need something like (newValue == 'true')


Perhaps you can share your script so that we can see the context of your issue?

This is a simple onLoad script to display an alert if this value is true.

function onLoad() {
    var ip = g_form.getValue('u_ip');
    alert(ip);

    if (ip == 'true') {
        alert("Hello World");
    }

}

 

Thanks,

Stacy