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 used to be that the views were separate, so I have all my functions duplicated in record and create views if I need them in both. But judging from a very recent post here on the Community by Enrico Simonetti the create view extends the record view so you should be able to keep the function in record.js but I think you still need to define the event in create.js for it to trigger appropriately.

    Enrico Simonetti correct me if I'm wrong.

    FrancescaS

  • Hey Francesca Shiekh,

    I guess you are asking me this question because of my answer to this thread:How are record and create views supposed to work? 

    I am linking it so that other users have come context.

    Right this moment (as far as I know) the custom record.js and custom create.js of a module (custom/modules/<modulename>/clients/base/views/create|record/create.js|record.js) do not seem to extend each other directly, down the chain of extension.

    create.js extends record.js controller on all the non-module specific (as in clients/base/views and custom/clients/base/views) controllers.

    The order of extension of non-module specific controllers for creation is:

    • Custom create view
    • Core create view
    • Custom record view
    • Core record view

    In light of that, depending on if there is a core module create and record controller, you might be able to make them derive from each other on a case by case basis. You should be able to do that pretty easily for newly created custom modules.

    Just to double check, please give me few days to confirm the state of things but I think the above should help you get started

    Cheers

    ====================

    Update

    ====================

    After further investigation the above is correct. If functionality needs to be shared between a module's custom create.js and record.js controller, the most appropriate path forward is by leveraging a plugin that is added on both controllers.

    Plugins can be found on clients/base/plugins normally within the specific module, and then it needs to be added within the appropriate view's controller. An example can be 

    modules/KBContents/clients/base/plugins/KBContent.js used in multiple places including the record.js and create.js views controllers

    --

    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

  • 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