The value of True/false field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-29-2016 06:08 AM
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.
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-29-2016 06:25 AM
I already tried without the quotes as well! doesn't work!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-29-2016 07:55 AM
Soni,
There are some typos in your script; you missed some curly bracket in your script
Be aware that you have to put '{}' when your if statement has more than one row. in row 32, you've got
if(producer.Add_Delete=="Delete")
rec.u_active='false';
rec.update();
and it should be
if(producer.Add_Delete=="Delete") {
rec.u_active='false';
rec.update();
}
You also forgot to close the if statement at row 22 which is this one : if(rec.next()){
Unless I am wrong it should be closed before the row 30 which is if(producer.Add_Delete=="Add")
For the following condition (even if it is correct),
if(producer.Add_Delete=="Add")
rec.u_active='true';
I heavily recommend you to put it like following
if(producer.Add_Delete=="Add") {
rec.u_active='true';
}
That will make your script very clear.
the field that contains true/false value, is it a checkbox ?
if yes, just put as a following to make it true
rec.yourFieldName = true;
and for false
rec.yourFieldName = false;
Please Give a try now and let me know i that works or not
Kind regards
Do not feel shy to mark correct or helpful answer if it helps or is correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-29-2016 07:59 AM
Maybe the rec.update is after the if/else statement. in this case, I recommend :
if (...) {
// your logic
} else {
// YOUR LOGIC
}
rec.update();
Kind regards
ZA
Do not feel shy to mark correct or helpful answer if it helps or is correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-29-2016 08:05 AM
Thanks for your help AKb ,
but still doesn't work. the field is on the table and it's a true false (it is not a check box) ; I don't have it on my record producer.
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];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-29-2016 08:12 AM
I think you don't need the rec.update() in record producer.