Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Setting value to Boolean field using GlideRecord

RahulY00040
Tera Expert

Hello friends,


When i try to do below, it fails (does nothing) with string "True" whereas works well with string "False". I tried with string "true" and it worked, but want to check, why it wouldnt work with string "True".

 

var gr=new GlideRecord('cmdb_ci_computer');
gr.get('xxxxx');
//gr.setValue('virtual',"False");
gr.setValue('virtual',"True"); //Virtual is the BOOLEAN field.
gr.update();

 

Thanks in advance,

Rahul

1 ACCEPTED SOLUTION

Brad Bowman
Mega Patron

Boolean values are true and false or "true" and "false".  I would submit that the script does not work well with "False", rather it's not setting a value the same as "True" is not setting a value, so the result in both cases is an empty checkbox/false value since a boolean has to be either true or false.

View solution in original post

2 REPLIES 2

Brad Bowman
Mega Patron

Boolean values are true and false or "true" and "false".  I would submit that the script does not work well with "False", rather it's not setting a value the same as "True" is not setting a value, so the result in both cases is an empty checkbox/false value since a boolean has to be either true or false.

Ankur Bawiskar
Tera Patron

@RahulY00040 

setValue() bypasses display-value and writes raw value directly

so you should pass either "true" or "false"

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader