Skip to Content
avatar image
Former Member

How to store my checkbox values as 1 for true and null for false in hana db TwoWay binding?

Hello guys,

I have an application in SAPUI5 with a lot of checkboxes.

We store the checkboxes values as TINYINT in the database, how can I convert them to send in the update batch request 1 for true and null for false values?

I tried with formatter, but it doesn't work in TwoWay binding. Tried to convert this old snippet

oCheckBox.bindProperty("checked", {path: "/some_path", type: BoolString, mode: sap.ui.model.BindingMode.TwoWay});

in my xml view, because this is js view, unfortunately didn't work also.

Could you give me an example with a code snippet or an idea how to fix this issue, please?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 28, 2017 at 07:01 AM

    Hello guys,

    I found a solution about this and want to share with you:

    You can create your custom data type in SAPUI5, which inheriting from sap.ui.model.SimpleType and you can change the logic in the functions formatValue (called whenever the value in the model is changed to convert it to the type of the control property it is bound to) and parseValue (called whenever the user has modified a value in the UI and the change is transported back into the model). validateValue is called to check additional constraints, like minimum or maximum value, and throws a ValidateException if any constraints are violated.

    You can find the code snippet from our app below:


    sap.ui.model.SimpleType.extend("sap.ui.model.type.Boolean", {

    formatValue: function(oValue) {

    if (oValue === 1) {

    return true;

    } if (oValue === null || oValue === 0)

    { return false; }


    parseValue: function(oValue) {

    if (oValue === true) {

    return 1; }

    else if (oValue === false) {

    return 0;



    validateValue: function(oValue) {

    return oValue;




    <CheckBox text="{i18n>hdCheckBox}" selected="{path: 'hd', type: 'sap.ui.model.type.Boolean'}" editable="true" enabled="true" visible="true" width="auto" textDirection="Inherit"/>

    Thanks for your answers!

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 18, 2017 at 07:00 AM

    Use formatter function in your XML view control for the checkbox. So, when the user selects a checkbox this function is invoked and you can manipulate checked to your preferred value(for HANA DB) and vice versa(when the user unchecks the field.

    Look up on formatter functions in XML views.



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Sharath,

      It was the first try, unfortunately formatter doesn't work in TwoWay binding as I said.

      Thanks anyway.

  • Aug 18, 2017 at 03:44 PM

    your checkbox can use Expression Binding on the checked property as follows:

    var oCheckbox = new sap.m.Checkbox({ checked: "{= ${/some_path} == 1 }" });

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 01, 2018 at 08:09 AM

    Hi Sergio,

    Could you tell me how can we achieve this with JS views.

    Sincere regards,
    Meghna Anand

    Add comment
    10|10000 characters needed characters exceeded