How can I run a function when a parent Record View function runs?

I am building a customisation that extends a view (BaseProductBundlesQuoteDataGroupListView) that already extends the BaseRecordView and I need one of my custom functions to run after a new record is saved.

I've found that there are save() and handleSave() functions in BaseRecordView, but I have been unable to extend or _.wrap() them in any way I could find. Running my function on this.context.get('parentModel').on('save') or 'saved' does not work at all. I have also tried runing it on this.parent.context.on('button:save_button:click'), but nothing happens.

Do you know how to do this efficiently without messing around with creating an additional view and duplicating my custom methods?

May I should build this the other way around and extend  the Quotes record view, getting and using the child view of BaseProductBundlesQuoteDataGroupListView?

Parents Reply Children
  • It actually would probably be better to use an Advance Workflow to acheive your logic

  • As already mentioned. Place all the logic you want in the create.js view.

    Another option, if you do not want to copy code between record and create views is to add another controller for the bean in general to the JSGroupings sidecar grouping. Point it to a file like custom/modules/Products/lib/bean.js.
    In this controller you can extend on the bean's prototype:

    ({

       app.events.on("app:sync:complete", function () {

          if (!app.metadata.getModule("Products")) {
          return;
       }

       var productClass = app.data.getBeanClass("Products");
       var oldInitialize = productClass.prototype.initialize || app.data.beanModel.prototype.initialize;

       _.extend(productClass.prototype, {
          initialize: function (options) {
             oldInitialize.call(this, options);
          },

       });

    })

    and manage any events there. Any changes made to the bean there will reflect regardless of wether you are in create or record view.