How to call js function on record view of custom field

How to call js function on record view of custom field

Screenshot from 2016-04-13 19:54:26.png

  • You can add some events in record.js or recordlist.js like:

    ({

      extendsFrom: 'RecordlistView',  // or RecordView

      initialize: function (options) {

      this._super("initialize", arguments);

      this.events = _.extend({}, this.events, {

      'click [name="some_button_name_of_fieldname"]':'SomeFunction'

      });

      this.context.on('list:some_button_name_of_fieldname:fire', this.SomeFunction, this);

      }

      // ...

    })

  • not works for me..

    i have one dropdown name   ex lead_field   , on value change need to call function and get that selected dropdown value.

  • So, practically you have an event like?

    this.events = _.extend({}, this.events, {

                'change [name="lead_field"]':'CallSomeFunction'

    });

  • Hello Thanks for reply its done like below but

    ({

         extendsFrom: 'RecordView',

        initialize: function(options) {

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

           this.model.on('change:lead_fields',this._updateLeads);

           this.model.on('change:template_module',this._updatetm);  // if add this its not working

        },

       

         _updateLeads: function(model)

         {

             if($('[name="save_button"]').is(":visible")){  

             desc = this.model.get("description");

             selectedval = this.model.get("lead_fields");

             setval = desc + ' ' + selectedval;

             this.model.set('description',setval);

             this.model.set('lead_fields',"");

         }

        },

       

        _updatetm: function(model)

         {

             if($('[name="save_button"]').is(":visible")){  

             this.model.set('description',"");

         }

        },

    })

    What is Wrong in This... if i write just one function working perfectly .. but 2 function not working

  • Hello Mehul Bhandari,

    I hope you doing well.

    Please put below code in your record.js and check. This code is work for me.

       ({
        extendsFrom: 'RecordView',
        initialize: function (options) {
            this._super('initialize', [options]);
           this.model.on('change:rating_c', this._disableEditForUserType, this);
        },
        _disableEditForUserType: function () {
            console.log("It's Working");
        }
    })
    

    Hope it will help.

    Let me know for more help.

    -BPATEL

  • Your events are missing this at the end

    this.model.on('change:lead_fields',this._updateLeads);

    this.model.on('change:template_module',this._updatetm);  // if add this its not working

    It should be:

    this.model.on('change:lead_fields',this._updateLeads, this);

    this.model.on('change:template_module',this._updatetm, this );

  • Thanks All its working on RecordView .. and Same want to apply on Create ..

    i have create custom/modules/Mod_Name/clients/base/views/create/create.js

    ======  below code not working ..  what is wrong ..

    ({

         extendsFrom: 'CreateView',

        initialize: function(options) {

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

           this.model.on('change:lead_fields',this._updateLeads, this);

           this.model.on('change:template_module',this._updatetempmod, this);

        },

       

         _updateLeads: function(model)

         {

             

                 console.log("Lead Fields"); 

             desc = this.model.get("description");

             selectedval = this.model.get("lead_fields");

             setval = desc + ' ' + selectedval;

             this.model.set('description',setval);

             this.model.set('lead_fields',"");

             

        },

       

        _updatetempmod: function(model)

         {

          

                 console.log("Template Fields"); 

             this.model.set('description',"");

          

        },

    })

  • Try to use create-actions instead of create

    Before

    custom/modules/Mod_Name/clients/base/views/create/create.js

    After

    custom/modules/Mod_Name/clients/base/views/create-actions/create-actions.js

  • Hello , tried out the latest 7.7 version yet?

    This blog post suggests we should be using create now instead of create-actions https://developer.sugarcrm.com/2015/11/17/createactionsview-changes-in-sugar-7-7-0/  in sugar 7.7  can't seem to trigger any custom js on the create panel ~

    Tried all permutations possible of create / create-actions .js

    They don't reside in custom > modules > clients > base view anymore ?

  • Hi Caim,

    You can try this path too:  custom/modules/<Module>/Ext/clients/base/views/