Forums › Forums › OroCRM › OroCRM – How do I? Questions › Add custom contact field to marketing list
This topic contains 3 replies, has 2 voices, and was last updated by Mike Kudelya 7 years, 6 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- September 28, 2016 at 8:18 am #29082
I have a custom contact field that is a many to one. When creating a marketing list it does not display as field.
How can I add it?
- CreatorTopic
- AuthorReplies
- September 30, 2016 at 1:11 am #29083
Hi,
Unfortunately for now we don’t have opportunity to add relation fields to marketing list.
September 30, 2016 at 4:36 am #29084Any suggested work arounds? We can turn this field into account names. Will that allow us to export the marketing list with the account name plus the contact fields?
October 3, 2016 at 10:19 am #29085Hi,
Here is example how you can add phone number of call entity (in my case) in lead marketing list:
Listener:
PHP1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162<?phpnamespace Custom\Bundle\OroBundle\EventListener;use Oro\Bundle\DataGridBundle\Datagrid\Common\DatagridConfiguration;use Oro\Bundle\DataGridBundle\Datagrid\ParameterBag;use Oro\Bundle\DataGridBundle\Event\PreBuild;use OroCRM\Bundle\MarketingListBundle\Datagrid\ConfigurationProvider;class MarketingGridListener{const FROM_PATH = '[source][query][from]';const SELECT_PATH = '[source][query][select]';const COLUMNS_PATH = '[columns]';const JOIN_PATH = '[source][query][join][left]';const MAIN_ENTITY = 'OroCRM\\Bundle\\SalesBundle\\Entity\\Lead';const RELATED_ENTITY = 'callentity';const RELATED_ENTITY_FIELD_NAME = 'phoneNumber';/*** @param PreBuild $event*/public function onBuildBefore(PreBuild $event){$this->applyFilters($event->getConfig(), $event->getParameters());}/*** @param DatagridConfiguration $config* @param ParameterBag $parameters*/protected function applyFilters(DatagridConfiguration $config, ParameterBag $parameters){$isValid =$config->offsetExistByPath(self::FROM_PATH) &&strpos($config->offsetGet('name'), ConfigurationProvider::GRID_PREFIX) !== false;if ($isValid) {$from = $config->offsetGetByPath(self::FROM_PATH);if ($from[0]['table'] === self::MAIN_ENTITY) {$joinColumn = $from[0]['alias'] . '.' . self::RELATED_ENTITY;$entityJoin = [['join' => $joinColumn, 'alias' => 'relation_entity']];$selects = $config->offsetGetByPath(self::SELECT_PATH, array());$selects[] = 'relation_entity.' . self::RELATED_ENTITY_FIELD_NAME;$config->offsetSetByPath(self::SELECT_PATH, $selects);$columns = $config->offsetGetByPath(self::COLUMNS_PATH, array());$columns['phoneNumber'] = array('label' => 'phone number');$config->offsetSetByPath(self::COLUMNS_PATH, $columns);$config->offsetAddToArrayByPath(self::JOIN_PATH, $entityJoin);}}}}Define the listener in services.yml:
YAML12345678parameters:custom_oro.listener.datagrid.marketing_list.class: Custom\Bundle\OroBundle\EventListener\MarketingGridListenerservices:custom_oro.listener.datagrid.marketing_list:class: %custom_oro.listener.datagrid.marketing_list.class%tags:- { name: kernel.event_listener, event: oro_datagrid.datagrid.build.pre, method: onBuildBefore } - AuthorReplies
The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.