Mautic Community Forums

Salesforce Integration Campaign Members filter not working after upgrade to Mautic 3

Your software
My PHP version is : 7.3.17
My MySQL/MariaDB version is (delete as applicable): 5.7.28

Updating/Installing Errors
I am (delete as applicable): Updating
Upgrading/installing via (delete as applicable) : Web AND Command Line

These errors are showing in the installer :

These errors are showing in the Mautic log :

Too many characters to post here (100k characters), but this error gets registered when I try to make changes to the segment integration campaign members:
mautic.WARNING: PHP Warning - array_flip(): Can only flip STRING and INTEGER values! - in file /var/www/vhosts//app/bundles/LeadBundle/Form/Type/FilterTrait.php - at line 275

These errors are showing in the upgrade_log.txt file (located in the root of your Mautic instance when an upgrade has been attempted - ensure you remove or redact any sensitive data such as domain names in the file path) :

Your problem
My problem is : I have upgraded from v2.16.5 to v.3.3.2 via v3.2.4. I had a couple of issues with the upgrade process - particularly hitting the ERR_MAUTIC_3_MIGRATIONS_IDENTIFICATION_FAILED error - which I resolved by manually running php bin/console doctrine:migrations:migrate

Our Mautic is connected to our salesforce instance and relies upon Salesforce Campaign Membership for building segments. Following the upgrade from v2.16.5 to v3.2.4, the Integration Campaign Members picklists on existing Segments are empty.

I reauthorized the Salesforce connector and re-ran synccontacts --integration=Salesforce but the Campaigns did not appear in the Integration Campaign Members picklists.

Knowing that v3.2.4 is not the latest release, I performed a command line upgrade to v3.3.2 – successfully applying the upgrade and schema updates. I then attempted a reauthorization of the plugin and a synccontacts again but no difference - the Integration Campaign Members picklist is still blank.

If I remove the existing Integration Campaign Members picklist from the Segment filters and then add a new Integration Campaign Members picklist, the list of Salesforce Campaigns appears in the picklist. However, if I attempt to save the Segment filters having selected a value in the picklist, I get the following error: This value is not valid.

If I run php bin/console doctrine:migrations:migrate, I get a WARNING! You have 134 previously executed migrations in the database that are not registered migrations. Other than that the results are No migrations to execute.

From the log file, it looks like something is unhappy, but I’m not sure exactly what!

Any help would be much appreciated…

Thanks!

We have several clients who experience the same issue. After some more digging I found out that it had nothing to do with migrations of the database. The problem has to do with some code changes from 2 to 3. Even with a clean install you cannot create a valid “Integration Campaign Members” filter for segments.

Luckily I found a quick fix that will make it work for our clients (fix will follow below), but this limits the functionality of this field. But since PHP and Symfony are not my strong suits I’m still looking for a complete fix. The problem has to do with the way, the optionlist is built. The fact that they are categorized seems to be the problem, I don’t think the form builder can handle this.

To fix this issue, you can remove the categorization. But this would make selecting the right campaign more difficult when there are more categories than Salesforce (in the code, a comment says that that is possible since 2.11.0). I still have to find a scenario where there are more categories than Salesforce, and the only scenario I could find are Marketing groups within ConnectWise (?).

To fix this issue, you only have to change one line of code. In the the CRM bundle LeadListSubscriber (plugins/MauticCrmBundle/EventListener/LeadListSubscriber.php), just change line 84 from

$choices[$integration->getDisplayName()] = $integrationChoices;

to

$choices = array_merge($choices, $integrationChoices);

This should fix the issue, but if you have a SF connection and a ConnectWise connection, this might make it difficult to see which is which. To fix this, you can add the following code just above line 84:

array_walk(
    $integrationChoices,
    function (&$choice) use ($integrationName) {
        $choice['label'] = $integrationName . ': ' . $choice['label'];
    }
);

This code will prefix the labels with the integration name, so that you can recognize them beter.

I’ll keep looking for a solution/fix for the issue with displaying the categories, but I’m not sure how long it’ll take.

For good measure, the function should look like this:

public function onFilterChoiceFieldsGenerate(LeadListFiltersChoicesEvent $event)
{
    $services = $this->helper->getIntegrationObjects();
    $choices  = [];

    /** @var CrmAbstractIntegration $integration */
    foreach ($services as $integration) {
        if (!$integration || !$integration->getIntegrationSettings()->isPublished()) {
            continue;
        }

        if (method_exists($integration, 'getCampaigns')) {
            $integrationChoices = $integration->getCampaignChoices();
            if ($integrationChoices) {
                $integrationName = $integration->getName();
                // Keep BC with pre-2.11.0 that only supported SF campaigns
                if ('Salesforce' !== $integrationName) {
                    array_walk(
                        $integrationChoices,
                        function (&$choice) use ($integrationName) {
                            $choice['value'] = $integrationName . '::' . $choice['value'];
                        }
                    );
                }

                array_walk(
                    $integrationChoices,
                    function (&$choice) use ($integrationName) {
                        $choice['label'] = $integrationName . ': ' . $choice['label'];
                    }
                );

                $choices = array_merge($choices, $integrationChoices);
            }
        }
    }

    if (!empty($choices)) {
        $config = [
            'label'      => $this->translator->trans('mautic.plugin.integration.campaign_members'),
            'properties' => ['type' => 'select', 'list' => $choices],
            'operators'  => $this->listModel->getOperatorsForFieldType(
                [
                    'include' => [
                        '=',
                    ],
                ]
            ),
            'object' => 'lead',
        ];
        $event->addChoice('lead', 'integration_campaigns', $config);
    }
}
2 Likes

This problem still persists in Mautic 4.1.1 - and the solution posted here still fixes it…
THANKS bas ! :slight_smile: