type of gr.active

RAHUL Khanna1
Mega Guru

Hello Folks,

can any body clear me on this ...

var gr = new GlideRecord('sys_user');

gr.get('user_name', 'XXX');

1) gs.print(typeof gr)

2) gs.print(typeof gr.active);

both are object type ...what is the difference between object-1 and object-2

I could get all the properties of all the object-1 , where as I could not in object-2.

Also ----> gs.print(gr.active == true) <------------> gs.print(gr.getValue('active') == true)---------->gs.print(gr.getValue('active') == 'true')

can any body please make me understand above statements.

 

7 REPLIES 7

AbhishekGardade
Giga Sage

Hello Vinod

1) gs.print(typeof gr) : its gliderecord object if the table / record

2) gs.print(typeof gr.active); its type of the active field

3) gs.print(gr.active == true) : gr.active will fetch the value from record which you filtered out from table by adding query. 

4) gs.print(gr.getValue('active') == true) : TRUE AND FALSE are boolean values which is predefined in servicenow. here true is boolean value

BOTH gr.active and gr.getValue('active') will give the same result. but gr.getValue('active') is recommanded

5. gs.print(gr.getValue('active') == 'true') : TRUE AND FALSE are boolean values which is predefined in servicenow. here true is considered as string value not boolean.

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

vkachineni
Kilo Sage
Kilo Sage

gr.active is a true/false type

 

 gs.print(gr.active == true) you are comparing two booleans

 

 gs.print(gr.getValue('active') == true) you are comparing string to boolean. However javascript does the type conversion.

Read about == VS ===

 

gr.getValue('active') == 'true' you are comparing string to string

 

 

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

var gr = new GlideRecord('sys_user');
gr.get('user_name', 'admin');

gs.print(gr.active == true);//--->true
gs.print(gr.getValue('active')==true)//---->true
gs.print(typeof gr.getValue('active') )//-->string
gs.print(typeof 'true' )//-->string
gs.print(gr.getValue('active')=='true')//---->can you please guess and explain me.

RAHUL Khanna1
Mega Guru

Thnaks for the reply , 

I think I am looking for the following.

 

1) var gr = new GlideRecord('sys_user');

2) gr.get('user_name', 'XXXX');

 

I understand from Background script that gr is a glide record object and was also able to access the properties of it.

Of I am tryting to print type of gr.active it is still showing as object, if this is also object then what arre its properties.

 

also can I equal Object with a boolean value ----> like if(gr.active == true)