Set a checkbox when another field has content

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • just_me
    Junior Member
    • Jul 2019
    • 25

    Set a checkbox when another field has content

    It seems to be easy, but in the end i have found different information about it.

    I have a field, "Last checked on", which might hold a date or not. and i have a boolean field, which is named "Dataset checked". Now i want to have the boolean field to be set to true, when the field "Last checked on" has an entry.

    I tried this as formula in my entity accounts:

    Code:
    ifThen($cLastchecked on != '',
    $cDatasetchecked = 'true',
    );​
    The codechecker says, syntax is ok. But, when i change the value of Last checked from nothing to today's date, the checkbox won't be checked.

    In details page on account there is the Last checked on field, and the boolean field is only visible in list view.

    Would i need the boolean field also on details page?

    I also saw some code like this:

    Code:
    ifThen($cLastchecked on != '',
    $cDatasetchecked = '1',
    );​​
    which i gave a shot as well, with or without ', it didn't matter, and wouldn't work as well.

    What am i missing or am i barking up the wrong tree?

    Just came back to Espo after a couple of years, and try to find my way around it.

    Really appreciate help, even if it sounds stupid to most of you :-)

    Thanks and best
    j_m

    PS: the bing AI suggested this Code:

    Code:
    // Define a custom dynamic handler
    define('custom:my-dynamic-handler', ['dynamic-control:enhanced-dynamic-handler'], function (Dep) {
    return Dep.extend({
    
    controlFields: function () {
    // Check if the target field is not empty
    if (this.model.get('target_field_name') !== '') {
    // Set the checkbox field to true (checked)
    this.model.set('checkbox_field_name', true);
    } else {
    // Optionally, uncheck the checkbox if the target field is empty
    this.model.set('checkbox_field_name', false);
    }
    },
    
    // Initialize the handler
    init: function () {
    Dep.prototype.init.call(this);
    
    // Add a listener to the target field changes
    this.listenTo(this.model, 'change:target_field_name', function () {
    this.controlFields();
    }, this);
    
    // Initial check on form load
    this.controlFields();
    },
    
    });
    });​
    But i don't get where to put it, whether in client/custom/scr or in custom /whatever as .js or .json and how to move on from there. If i put it in the formula editor for entity accounts, it wouldn't work either.
  • Athensmusic
    Member
    • Feb 2020
    • 51

    #2
    ifThenElse(cLastchecked, cDatasetchecked=true, cDatasetchecked=false);​​

    Comment

    • just_me
      Junior Member
      • Jul 2019
      • 25

      #3
      Thank you, this did the trick :-) I was growing grey hair with trial and error and this helped me a lot.

      Comment

      Working...