The Zurich release has arrived! Interested in new features and functionalities? Click here for more

The value of True/false field

sonita
Giga Guru

In my table I have a field called u_active and the type is True/False.

In my record producer I have a drop down field the values of Add and Delete.

When a record is submitted with 'Add' flag the u_active field should be shown as true; and when a record is submitted with 'delete' flag the u_active field should be shown as false.

(we will keep the deleted records in the database as well)

I have set the default value of the u_active field as true in the dictionary.

in the script section of my record producer I have this code:

if(producer.Add_Delete=="Add")

rec.u_active='true';

if(producer.Add_Delete=="Delete")

rec.u_active='false';

            rec.update();

} else{

rec.initialize();

            rec.u_src_grp_no = group_ids[x];

            rec.u_cid = producer.u_cid;

            rec.u_renewal_month = producer.u_renewal_month;    

rec.u_ctb_prgm_start_dt=producer.u_ctb_prgm_start_dt;

    rec.u_ctb_prgm_end_dt=producer.u_ctb_prgm_end_dt;

rec.u_req_type=producer.Add_Delete;

            rec.insert();

But it does not work!!!!!!!!!!!!! it always shows True. Any help would be greatly appreciated.

24 REPLIES 24

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You're setting the field correctly in the script. My guess would be that your conditions aren't working. I would validate that the name of your variable is indeed Add_Delete and that the values of your choices are correct. They are case sensitive.


find_real_file.png



find_real_file.png


Brad Tilton
ServiceNow Employee
ServiceNow Employee

In that case your syntax is ok. Could you post the whole script? I'm guessing the issue may be there somewhere. You might also add some logging to the RP to check to see if the value is being set and then overwritten somewhere else.


FYI: I have set the default value as true in dictionary .



producer.redirect="home.do";


current.u_req_type=producer.Add_Delete;



var json = new JSON();




var group_ids = producer.u_src_grp_no+'';


group_ids=group_ids.split(',');


gs.addInfoMessage(json.encode(group_ids));


gs.addInfoMessage(group_ids.length);




if(group_ids.length > 1){




for (var x = 1; x < group_ids.length; x++){


var rec = new GlideRecord('u_ctb');


///First, query to see if there's a record already with the same Client/Group combination


rec.addQuery("u_src_grp_no", group_ids[x]);


rec.addQuery("u_cid", producer.u_cid);


rec.query();


if(rec.next()){


            rec.u_src_grp_no = group_ids[x];


            rec.u_cid = producer.u_cid;


            rec.u_renewal_month = producer.u_renewal_month;    


rec.u_ctb_prgm_start_dt=producer.u_ctb_prgm_start_dt;


    rec.u_ctb_prgm_end_dt=producer.u_ctb_prgm_end_dt;


rec.u_req_type=producer.Add_Delete;



if(producer.Add_Delete=="Add")


rec.u_active='true';


if(producer.Add_Delete=="Delete")


rec.u_active='false';


            rec.update();


} else{


rec.initialize();


            rec.u_src_grp_no = group_ids[x];


            rec.u_cid = producer.u_cid;


            rec.u_renewal_month = producer.u_renewal_month;    


rec.u_ctb_prgm_start_dt=producer.u_ctb_prgm_start_dt;


    rec.u_ctb_prgm_end_dt=producer.u_ctb_prgm_end_dt;


rec.u_req_type=producer.Add_Delete;



            rec.insert();


}


      }


}


//gs.addInfoMessage(group_ids[0] + "   the first value");


current.u_src_grp_no=group_ids[0];