Selecting proper company in email token

Your software
My Mautic version is: 2.16.2
My PHP version is: 7.2

Your problem
My problem is:
I have a situation that one contact can have multiple companies. And creation is working as expected, both from dashboard and API.

Now, I have a campaign to notify the user on the status of their companies (Company A trial expired, Company B payment success etc.).

I created segments that contains the contacts based on company fields and then I have campaigns that are run for various segments.

All that works just fine until the email is sent. Mautic always take the information from primary company which results in sending misleading information to the contacts.

So for example: Company A is primary company for a contact.

Company A have trial expired, the campaign is run and the contact received proper email with Subject Company A trial expired

Howerver, in case of company B having their payment failed the campaign should send email with subject Company B have failed payment. But instead, the contact received subject Company A have failed payment

I guess this is a bug, or there is some work around it which I canā€™t figure out.
Did anybody else came across similar issue?

Steps I have tried to fix the problem:

Hello @goranculibrk,

To start with I suggest you upgrade Mautic to the latest version :wink:
Can you explain your business use case? Why do you have a contact that is attached to two companies?

Pierre

I have many contacts that are atteched to multiple companies :smiley:

Hello @joeyk,

Thanks for your feedback.
What is the concrete business use case? What do you need it for?

Pierre

There are many many :slight_smile:

Letā€™s say you have many agencies (stored as contact) who serves multiple partners (store as company).
One agency can have many companies. Companies have different custom fields, for example

  • logo color
  • logo size
  • logo material

You as the provider through agencies you can notify all your agencies who have partners (saved as company) in case there is a discount in yellow, metal logo materials.

@goranculibrkā€¦ Did you fix this problem? If so, how?

@joeyk maybe you can help me with this one? Or someone elseā€¦I find it an very interesting case :slight_smile:

We are trying to set up Mautic as an resevervation tool. We connect reservation software with an API to retrieve reservations and send them to Mautic. In Mautic we use companies as reservations. So the reservation ID is the company name. The issue I ran into is that when a contact has multiple reservations (companies) and I want so send an e-mail with company custom fields tokens, Mautic will always pick the information from the primary company.

So for example: I have an arrival date as a custom company field. 2 weeks before the arrival date the contact should get an email with the reservation ID and information about the accommodation. But if a contact has multiple reservations it will always get an email with the reservation ID form the primary company, which is not always the right ID.

Is there some smart solution to fix this?

What if someone has 2 reservations?
One in 12 days another one in 10 days?

You can btw use hacks to switch primary company.

If the reservation in 12 days is made later than that will be the primary company. When I send a mail for the reservation in 10 days that mail will be filled with information from the reservation that is made for 12 days.

I thought about switching primary company with a campaign action, but I couldnā€™t come up with a solution on how to change the primary company to the right one?

What do you mean with hacks?

Well, first of all:
The last company is always the primary company.
Wouldnā€™t that solve your problem?

Did you look into custom objects?

That doesnā€™t solve the problem.

For example: I have one reservation (001) made on 1-1-2024 with an arrival date of 1-3-2024. And I have another reservation made on 1-2-2024 (002) with an arrival date of 1-4-2024. So the reservation for 1-4-2024 (002) is the primary company.

If I want so send mails, 2 weeks before the arrival date. Then on 15-2-2024 a mail will be send for reservation 001, but because the primary company is 002 all the information in the mail will be about 002 instead of 001.

The custom plugin seems a great solution, but I can get it to work, so I was hoping for a workaround. I also commented on: How to install Acquia's Custom Objects plugin? - #80 by kafoalex.

Then I guess I have dive deeper into the custom objects plugin.

Thanks for your replies. Really appreciate it!

1 Like

There is one more option.

You can place all the reservations in a form. The form entries are connected to a person, and you can have a one to many relationship, just like with companies, but you donā€™t have to hack the system. At least not the same way.
Mautic Twig Templates Plugin is able to parse, manage, compute form entries.
Here is the plugin.
Iā€™m not sure if parsing form results is fully documented, but Iā€™m happy to hop on a call and guide you through it.
Iā€™m also building an event platform with Mautic for a client, and this plugin helped me a lot.

Yes, I tried to set that up yesterday, but you canā€™t use the formfield token in a campaign mail. Only as an form action. So I stopped there.

But I havenā€™t thought about the Twig Templates Plugin. I now see they have a {{ formresults }} option. Thatā€™s looks like a great option. Iā€™ll try this next week.

Iā€™m also interested in the event platform :). Maybe good content for your blog?

Hi @joeyk,

I installed the Mautic Twig Templates Plugin. The {{ formresults }} option gave me the same problem. As soon as there a multiple form submissions the plugin uses the information from the last submission. And that is not always the right information.

I didnā€™t really find helpfull information about parsing form result, so if you can help me further? That would be greatā€¦

I ran into this as well now. Iā€™ll report thisā€¦

1 Like

For information on how to process form results using the Twig Templates library, visit Twig Templates snippets library.

If you encounter any issues, feel free to contact me.

hi @kuzmanyy,

Thanks for sharing. The issue I ran into is that I get the wrong info in my emails. I explained here in this topic before.

The problem is that if someone submits multiple forms, the mail I send will always contain the data from the last form submission. And sometimes Iā€™ll need the information from an older submission. Is there a way to force Mautic to send the formresult from a previous submission?

Yes, the link provided includes an example from the most recent submission or the processes related to submissions and contacts.

You can use two tokens {{formresult}} or {{formresults}}

1 Like

Hi there,

It works great. I didnā€™t try the formresults yet. I also got it working with the following snippet:

{% for company in contact.companies %}
{% if company.arrivaldate == ā€œnowā€|date_modify(ā€˜+14 dayā€™)|date(ā€œY-m-dā€) %}

I set up a segment to check if the arrival date is 14 days in the future and then it will start a campaign to send the email with the right info. After the mail is sent the contact is removed from the segment.

@joeyk: Iā€™m wondering how this works? I was expecting that after the contact is removed from the segment it would be added again a couple of minutes later when the segment/cron jobs checks if contacts match the filter settings? But that didnā€™t happen. Is that normal behaviour?

Hi @joeyk isnā€™t that how its working since the very beginning? Otherwise - how will you select one form submit vs. the other?