one to many relationship from converting lead

Hello SugarCRM community

I would like to add new one-to-many relationship from the lead page to my custom module.
As I understand it, I have to use a logical hook, but I cannot implement it.
Could you help me?
I have a lot of difficulties with this, for example, how can I get the current ID? or is it not needed at all
Here is an example of my use case:
I would like to have on the lead page such fields as contact information with two prefixes home and work.
And so that the field with the home prefix after conversion of the lead is automatically recorded as a record of a one-to-many relationship in my custom module. And fields with a worker prefix will be created in another one-to-many relationship record.
I would like a new record to be created for each prefix.
For example, for each fields, home mobile, work mobile, instagram, email, work email, so that all these fields would be as separate records in the subpanel of my custom module. (one-to-many relationship)

I hope I was able to explain it correctly.
I'm not very good at this, I wanted to ask you for advice, maybe someone came across a similar one and could share an example of my code that I could change

Thanks

Parents
  • Hi Dima,

    You do not need a logic hook to add a new relationship. You can create a one-to-many relationship in two places - either in Module Builder when you first design your custom module (it will be m:1 then), or in Studio after the custom module has been deployed/installed into your environment. It sounds like you may have already created the relationship, but for reference, the guide is here: https://support.sugarcrm.com/Knowledge_Base/Studio_and_Module_Builder/Understanding_Relationship_Creation_Options/#Creating_Relationships

    Let's move into getting data into this custom module.

    It sounds like each row of this custom module represents another piece of contact information, e.g.

    id field value
    abc home (012) 345 678
    def mobile (012) 678 912
    ghi work (013) 294 103

    You can populate data within the custom module using SugarBPM (requires Ent/Sell/Serve):

    1. Create a new process definition based upon the Leads module, triggering upon new records
    2. Using the "Add Related Record" action, select your custom module
    3. For the 'value' field (or however you've called it), use the Field Selector to select the corresponding data from the Leads module.

    Some tips on making this efficient:

    • You will need one of these "Add Related Record" actions for each piece of contact information you're tracking.
    • You will likely want an exclusive gateway in front of each of these actions to assess whether you need to add a related record or not (based upon whether that field contains valid data in the Leads module - non-empty being a good start!)
    • You are encouraged to make the very first step after the process def triggers, a "Wait 1 min" activity, so that all record creation is queued in the background and does not have any impact upon performance.

    All done without a single line of code - good luck!

    Adam

Reply
  • Hi Dima,

    You do not need a logic hook to add a new relationship. You can create a one-to-many relationship in two places - either in Module Builder when you first design your custom module (it will be m:1 then), or in Studio after the custom module has been deployed/installed into your environment. It sounds like you may have already created the relationship, but for reference, the guide is here: https://support.sugarcrm.com/Knowledge_Base/Studio_and_Module_Builder/Understanding_Relationship_Creation_Options/#Creating_Relationships

    Let's move into getting data into this custom module.

    It sounds like each row of this custom module represents another piece of contact information, e.g.

    id field value
    abc home (012) 345 678
    def mobile (012) 678 912
    ghi work (013) 294 103

    You can populate data within the custom module using SugarBPM (requires Ent/Sell/Serve):

    1. Create a new process definition based upon the Leads module, triggering upon new records
    2. Using the "Add Related Record" action, select your custom module
    3. For the 'value' field (or however you've called it), use the Field Selector to select the corresponding data from the Leads module.

    Some tips on making this efficient:

    • You will need one of these "Add Related Record" actions for each piece of contact information you're tracking.
    • You will likely want an exclusive gateway in front of each of these actions to assess whether you need to add a related record or not (based upon whether that field contains valid data in the Leads module - non-empty being a good start!)
    • You are encouraged to make the very first step after the process def triggers, a "Wait 1 min" activity, so that all record creation is queued in the background and does not have any impact upon performance.

    All done without a single line of code - good luck!

    Adam

Children
  • Hi Adam

    Thanks for your reply

    I think this is almost what you need

    but I would like to ask you something else

    How can I set up automatic creation of relationships from my fields after lead conversion (Converting lead)?

    Example, I create a lead and fill in all the fields. Next, I convert the lead and get a new contact and  new account (they have relationship 1-to-2 )


    But how can I make sure that at this step, when converting a lead, new relationships 1-to-2 are created in my custom module and attached to the Contact created from the lead?