Duplicate "Relate to" in email module

I’ll explain the problem:
when I send an email, after selecting the template, I select the “Relate to” field, here I choose a reference module, generally I select “Contacts”, in this way the contact info can be shown in the body of the email ($ contact_name, etc. .), if I select “Opportunity” I cannot view the “Contacts” info and vice versa.
In a nutshell I need the data from both the Contacts module and Opportunities or other modules, to be inserted then in the body of the email.
Do you have any idea how to solve the problem?
Could a possible solution be to duplicate the “Relate to” field? In order to relate both Contacts and Opportunities. If so, where do I find the related HTML files?
Thanks

Sorry, it’s not as simple as adding a second relate field. You’d also have to add code to fetch the variables.

I solve this in my PowerReplacer SuiteCRM add-on, where you can fetch anything from any related or unrelated module.

I can leave you my original notes about where this code flows through, in case you want to try making changes yourself:

Code flow 1 (Compose)
-----------------
EmailsController actions_save 
> replaceEmailVariables 
> EmailTemplate::parse_email_template
> preg_match_all
> substr_replace

Sorry, but I didn’t understand very well:

Code flow 1 (Compose)
-----------------
EmailsController actions_save
> replaceEmailVariables
> EmailTemplate :: parse_email_template
> preg_match_all
> substr_replace

how should i proceed? What files should I consider?

Sorry, I went too fast :smiley: my notes are just stuff I use to Find in Files in PhpStorm, to quickly get to the files.

But here you go:

parse_email_template is a function in modules/EmailTemplates/EmailTemplate.php - the rest of the lower-level functions are called there

This gets called from replaceEmailVariables in modules/Emails/EmailsController.php

This in turn gets called from action_send in the same file (which is what is triggered when the user hits “Send” in the Email Compose window.

I hope this helps. Good luck.

Ok, now it’s a bit clearer … from what I read in the code of parse_email_template, it is passed $focus_name which is the name of the selected module (Relate to), and once it knows the module, it substitutes the variables of the email template with the variables of that module. What I can’t do and understand, however, is how to tell it to replace other variables as well, not just those of the selected module

It’s not ready for that, so all you want to happen needs to be done by hand

If variable is from module X, fetch the related bean from X, replace the text

:man_shrugging: