Send additional information to the logic hook

I was familiar with Sugar 6.5. Now I'm learning how to work with recent versions but is hard to change the mindset.

I'm working in a custom module. I've created a custom button to duplicate a record and create a new version of the record.
I've extend record view and I'm able to create the duplicate record using the drawer.open layout:create

I need to send some extra information for the logic hook before_save so I can diferenciate from a create record and a new version create record.

How can I send additional information to the logic hook?
For example send a control variable like subaction=newVersion

Is it possible for someone to direct me towards a path?

Parents
  • Welcome to the new world of Sugar Sidecar  

    I remember being in your shoes and totally overwhelmed by the new framework and having to learn Javascript, you will get the hang of it, and you'll love the changes.

    At one point I put together a post listing my favorite resources and there were a lot of great suggestions, but my post seems to be gone.

       still has some good pointers here:  Favorite Sugar 7 Developer resources 

    If I understand correctly you have two types of create you want your users to be able to work with:

    => create a new version of the record (custom)

    => create a clean new record (standard)

    The latter is handled by the standard "Create" functionality, while the one you are working on as a custom action is the "create a new version of this record".

    When you create a new version you want to copy the information from the old record but also do something else, which in your case you are thinking to do in a before_save logic hook.

    You have two things to address:

    - the duplication of the record

    - the addition of the extra information for the before_save logic hook

    How you tackle this will partly depend on what this "extra information" is and what you need the logic hook to do.

    For the duplication of the record there is  an existing action to "duplicate"

    This action executes some code that populates the create view with a copy of the record you are on.

    in custom/modules/<your module>/clients/base/view/record/record.php 

    you can add the button:

                  array (
                    'type' => 'rowaction',
                    'event' => 'button:duplicate_button:click',
                    'name' => 'duplicate_button',
                    'label' => 'LBL_DUPLICATE_BUTTON_LABEL',
                    'acl_module' => 'wcont_WolframContracts',
                    'acl_action' => 'create',
                  ),

    The action that the click takes can be seen in the orignal sugar controller:

    clients/base/views/record/record.js

    In the script in the "delegateButtonEvents" you will se that the click action calls a function called "duplicateClicked"

    this.context.on('button:duplicate_button:click', this.duplicateClicked, this);

     Just as you were used to extending classes in v6.5 you can similarly extend the controller's functionality in your custom directory.

    So  in custom/modules/<your module>/clients/base/record/record,js

    you can extend the Record view and either override or extend the duplicateCheck to do additional things

    ({
      extendsFrom:'RecordView',
      initialize: function(options){
        this._super('initialize',[options]);
      },
      duplicateClicked: function(){
        //this is where you extend what happens when the duplicate is clicked
        //you can maniuplate some of the data and then call the original function:
        
        this._super('duplicateClicked');
        
        //or put mechanisms in place to do something after the original is done with the copy.
      },
     })

    that could be set a flag on your module's record to say it was a copy, set a number (I do this with my custom contracts) to say this is a copy of contract 123, or whatever else you need to do.

    If you need to be able to have both an out-of-the box kind of duplicate and a custom duplicate, you can create your own action and define the button click in the initialize function to run your own function which executes the out of the box duplicateClicked and does other things.

    I hope this helps a little bit, if you can give us a better idea of what you are expecting your before save logic hook to do maybe there are other ways to achieve what you need.

    Hope this helps,
    FrancescaS

    PS. I learned a lot by looking at the original code and trying to reverse engineer what they are doing, the trick is knowing where to look Slight smile

  • Hi Francesca
    Thank you for your kind response.
    It's been difficult, but let's give it a try. ;)

    I'll analyze your suggestions and I'll share the result as soon as I get it.

Reply Children
No Data