Script include boolean always received as true even when its false

E_19
Giga Expert

Hi All,

I have a script include that has a number of GlideRecords to check or set field values on incident and change.

One value I am passing is the CR planning requested flag and if it is true do this else do that. The problem is that the value always comes in as true

Code snippets below:

//GR to get the boolean field for the company u_cr_planning_requested)

var ComCR = new GlideRecord('core_company');

                                  ComCR.addQuery(grT.company);

                                  ComCR.query();

                                    while (ComCR.next()) {

.....

....

      if (ComCR.u_cr_planning_requested) {

                  grCH.start_date = gs.nowDateTime();

                  grCH.end_date = dateTime();

  gs.log(ComCR.u_cr_planning_requested);

when I check sys logs the above log entry always has true even when its false.

Is some conversion missing my code?

Any suggestions greatly appreciated.

Thanks

Ellie

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Ellie,



Replace ComCR.addQuery(grT.company); with ComCR.get(grT.company);


View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Ellie,



Replace ComCR.addQuery(grT.company); with ComCR.get(grT.company);


balaji_charapal
Kilo Guru

Hi


Just try with below code, changes are in Bold


var ComCR = new GlideRecord('core_company');


                                  ComCR.addQuery(grT.company);


                                  ComCR.query();


                                    while (ComCR.next()) {


      if (ComCR.getValue('u_cr_planning_requested')) {


                  grCH.start_date = gs.nowDateTime();


                  grCH.end_date = dateTime();


}


  gs.log(ComCR.u_cr_planning_requested);



}


BALAJI40
Mega Sage

change the line of addQuery with,ComCR.get(grT.company); // if it returns sys_id


or ComCR.addQuery ('company',grT.company); if the field name is company