checkbox and setting 'Y' or 'N' value in database

I have a field in a table called ACTIVE_IND - this can be set to either ‘Y’ or ‘N’.

I would like to be able to use a checkbox to set this value in the database.
If the checkbox is checked I would like to store ‘Y’ - if the checkbox is unchecked I would like to store ‘N’.

Checkboxes, as I understand them translate to ‘1’ (if checked) and ‘0’ (if unchecked).

How do I translate ‘1’ to ‘Y’ and ‘0’ to ‘N’ (I am very new to Servoy, by the way)

Thanks in advance
Mark

Maybe by using a valuelist on that field.

It wil show Y and N to the user and write 1 or 0 to the database.

Y|1
N|0

See the servoy developer user guide.

Regards

I ended up doing the following and it works exactly how I wanted it…

I’m using a calculation combined with an onDataChange event.

  1. I created a calculation ‘display_active_ind’ in the same table to return 0 or 1
    if(active_ind == 'Y')
        return 1;
    return 0;
  1. I then put the check box field on the form. It’s dataprovider should be the calc display_active_ind. I added an onDataChange handler to the checkbox
    var value = arguments[1]; //   the NEW value (old is arg[0])
    if(value)
        active_ind = 'Y';
    else
        active_ind = 'N';

Works like a charm!

P.S. thanks Sean :D

Hi Mark,

You could do all this I think with one valuelist, one checkbox and one method.
Create a valuelist with the 1 value ‘Y’ (no quotes of course).
Attach that on your checkbox field.
Add a onDataChange method on this checkbox field where you let it store a ‘N’ when the new value is ‘0’.
This way you get ‘Y’ and ‘N’ in your database while using a single checkbox.

Hope this helps.