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?

  • I could, but both of those options would require the custom function to be completely re-written into a different language - PHP or Advanced Workflow. I'm trying to avoid that. Wouldn't matter much in a one-time scenario, but this happens and will happen often.

  • Thanks, that helps!

    Is there no way for the custom record view to expose one of its functions to be available to the custom create view?

    I'm thinking if custom Backbone events (listenTo(), etc.) could be used to accomplish this effectively?

    I can't find any documentation on plugins besides Outlook plugins and such. Where can I find information on how to do that?

    Would the plugin be different from a JS file in JSGroups?

  • We do have a building block plugin sample with a related Sugar Developer blog post that should help you in the process of building a plugin: BuildingBlocks/packages/CssLoader at master · sugarcrm/BuildingBlocks · GitHub  

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • 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.

1 2