# Selecting proper company in email token

**URL:** <https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547>\
**Category:** Product Support\
**Created:** [May 29, 2020, 9:47am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547 "2020-05-29T09:47:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![goranculibrk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/goranculibrk/32/127_2.png) [@goranculibrk](https://forum.mautic.org/u/goranculibrk)\
**Post date:** [May 29, 2020, 9:47am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/1 "2020-05-29T09:47:44Z")

</div>

**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:

---

<div class="post-metadata">

**Author:** ![pierre\_a](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pierre_a/32/7031_2.png) [@pierre\_a](https://forum.mautic.org/u/pierre_a)\
**Post date:** [April 25, 2022, 4:05pm UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/2 "2022-04-25T16:05:11Z")

</div>

Hello @goranculibrk,

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

Pierre

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [April 26, 2022, 8:01am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/3 "2022-04-26T08:01:21Z")

</div>

I have many contacts that are atteched to multiple companies 😃

---

<div class="post-metadata">

**Author:** ![pierre\_a](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pierre_a/32/7031_2.png) [@pierre\_a](https://forum.mautic.org/u/pierre_a)\
**Post date:** [April 26, 2022, 10:14am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/4 "2022-04-26T10:14:03Z")

</div>

Hello @joeyk,

> [@joeyk](#):
>
> I have many contacts that are atteched to multiple companies 😃

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

Pierre

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [April 26, 2022, 10:32am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/5 "2022-04-26T10:32:25Z")

</div>

There are many many 🙂

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.

---

<div class="post-metadata">

**Author:** ![klaasvna](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/klaasvna/32/957_2.png) [@klaasvna](https://forum.mautic.org/u/klaasvna)\
**Post date:** [February 23, 2024, 9:59pm UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/6 "2024-02-23T21:59:54Z")

</div>

@goranculibrk… Did you fix this problem? If so, how?

---

<div class="post-metadata">

**Author:** ![klaasvna](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/klaasvna/32/957_2.png) [@klaasvna](https://forum.mautic.org/u/klaasvna)\
**Post date:** [February 29, 2024, 10:22pm UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/7 "2024-02-29T22:22:45Z")

</div>

@joeyk maybe you can help me with this one? Or someone else…I find it an very interesting case 🙂

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?

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [March 1, 2024, 12:01am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/8 "2024-03-01T00:01:48Z")

</div>

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

You can btw use hacks to switch primary company.

---

<div class="post-metadata">

**Author:** ![klaasvna](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/klaasvna/32/957_2.png) [@klaasvna](https://forum.mautic.org/u/klaasvna)\
**Post date:** [March 1, 2024, 8:17am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/9 "2024-03-01T08:17:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [March 1, 2024, 8:27am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/10 "2024-03-01T08:27:00Z")

</div>

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

Did you look into custom objects?

> **[Acquia open sources Custom Objects plugin to extend Mautic’s capabilities](https://www.mautic.org/blog/community/acquia-open-sources-custom-objects-plugin-extend-mautics-capabilities)**
>
> Today we are delighted to share that Acquia has completed the process of open sourcing the Custom Objects plugin, a proprietary extension which was developed by Mautic Inc. in 2018 and has been a part of Acquia’s Campaign Studio since the acquisition...

---

<div class="post-metadata">

**Author:** ![klaasvna](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/klaasvna/32/957_2.png) [@klaasvna](https://forum.mautic.org/u/klaasvna)\
**Post date:** [March 1, 2024, 9:15am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/11 "2024-03-01T09:15:56Z")

</div>

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](https://forum.mautic.org/t/how-to-install-acquias-custom-objects-plugin/24204/80).

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

Thanks for your replies. Really appreciate it!

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [March 1, 2024, 10:41am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/12 "2024-03-01T10:41:37Z")

</div>

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](https://www.mtcextendee.com?via=plugins).  
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.

---

<div class="post-metadata">

**Author:** ![klaasvna](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/klaasvna/32/957_2.png) [@klaasvna](https://forum.mautic.org/u/klaasvna)\
**Post date:** [March 1, 2024, 11:00am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/13 "2024-03-01T11:00:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![klaasvna](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/klaasvna/32/957_2.png) [@klaasvna](https://forum.mautic.org/u/klaasvna)\
**Post date:** [March 8, 2024, 10:26am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/14 "2024-03-08T10:26:31Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [March 11, 2024, 7:55am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/15 "2024-03-11T07:55:18Z")

</div>

I ran into this as well now. I’ll report this…

---

<div class="post-metadata">

**Author:** ![kuzmanyy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kuzmanyy/32/390_2.png) [@kuzmanyy](https://forum.mautic.org/u/kuzmanyy)\
**Post date:** [March 11, 2024, 7:59am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/16 "2024-03-11T07:59:13Z")

</div>

For information on how to process form results using the Twig Templates library, visit [Twig Templates snippets library](https://mtcextendee.com/mautic-twig-templates-bundle-snippets-library/#features-05-222761).

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

---

<div class="post-metadata">

**Author:** ![klaasvna](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/klaasvna/32/957_2.png) [@klaasvna](https://forum.mautic.org/u/klaasvna)\
**Post date:** [March 11, 2024, 8:29am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/17 "2024-03-11T08:29:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kuzmanyy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/kuzmanyy/32/390_2.png) [@kuzmanyy](https://forum.mautic.org/u/kuzmanyy)\
**Post date:** [March 11, 2024, 11:33am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/18 "2024-03-11T11:33:31Z")

</div>

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

> **[Twig Templates snippets library](https://mtcextendee.com/mautic-twig-templates-bundle-snippets-library/#features-05-222761)**
>
> Available only If email is sent from send email to contact form action or send email campaign action with campaign form source

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

---

<div class="post-metadata">

**Author:** ![klaasvna](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/klaasvna/32/957_2.png) [@klaasvna](https://forum.mautic.org/u/klaasvna)\
**Post date:** [March 26, 2024, 8:20am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/19 "2024-03-26T08:20:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dirk\_s](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dirk_s/32/748_2.png) [@dirk\_s](https://forum.mautic.org/u/dirk_s)\
**Post date:** [March 26, 2024, 8:39am UTC](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547/20 "2024-03-26T08:39:12Z")

</div>

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

[Next page](https://forum.mautic.org/t/selecting-proper-company-in-email-token/14547.md?page=2)
