Get user who checked a checkbox and add the user in Relate field(Users module)

Hi, I have 3 fields: Checkbox, Relate field & Date in my custom module. All users can access the module but only few users can edit or update the fields. Here, when a user logs in and checked the checkbox, I need the get the user and update him in the relate field. Also I need to get the date when the checkbox is checked and update it in the date field. I didn't find calculated value option for Relate fields. Can this be possible using Studio? or do I need to make any code customizations? 

  • You can not accomplish these actions through Studio, but you can without big deal by customizing the view js controller (code customization).

    Basically you have to setup an event listener on the checkbox field and code the method to be called on changing the checkbox.

    initialize: function(options) {

       this._super('initialize', [options]);

       this.model.on("change:the_checkbox_field_c", this.triggerCheckBoxChange, this);
    },

    triggerCheckBoxChange: function(evt, value) {

       if(value == "true") { // or "1". I didn't try it

          this.model.set("user_relate_field_id", app.user.get('id'));

          this.model.set("user_relate_field_name", app.user.get('full_name'));

       }

    }

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi Andre, I don't have full_name property in Users module. Also I didn't get what is meant by user_relate_field_id. My field has name but can't find the id.