Add Campaign/Target List Support For A Custom Module

@pstevens what is the status on your attempts?

Can you get the Custom records added to the Target Lists at all? But then they don’t send when the Campaign runs?

Thanks @pgr for chiming in… I can get the custom module contacts to be added to a target list, no problem. I can add that target list to the campaign, no problem. The problem is that the “campaign” doesn’t see the targets. It counts “0” targets in list and then when you try to send you get an error that there are no targets found in target lists.


There are in fact contacts on the target list. I guess somehow it doesn’t recognize them as “targets”.

** by “Contacts” I mean my custom module “Freelancers” contacts. I have a relationship between Target Lists and Freelancers. Which allows me to add them to the target list.

I think this is where it’s counting:

Do your target entries get registered in prospect_lists_prospects relationship table, or is it in a different table, due to being a custom module? Have a look in your database.

Cool, I’ll check it out. I’ve been stumped on this one for a while. That’s a great clue!

OK w’ere on to something! My “Frelancers” are not in the prospect_lists_ prospects, but in in prospectlists_freelancers.

So, we’re getting closer, either we have to count prospect_lists_CUSTOM_MODULE_NAME in the code, or somehow have to add Freelancers to this table.

Cool. Remember that here we’re only battling the warning message when the count fails; but if we solve this one, we will probably hit a bump further ahead - getting the custom “prospects” added to the queue.

So I think we should look for a solution to make things work everywhere - something like tweaking the freelancers relationship to use the prospect_lists_prospects table too.

See how all these different relationships use the same basic table in the database:

–> https://github.com/salesagility/SuiteCRM/blob/master/metadata/prospect_lists_prospectsMetaData.php

Just an update, I’m making some progress with: http://web.archive.org/web/20140825230331/http://sugaruk.co.uk/blog/how-add-campaigntarget-list-support-custom-person-module-sugarcrm
There are a bunch of errors in the code, mostly with single quotes. Plus, there are some additional problems with whether or not the module name needs to be lowercase or uppercase in the code provided. Plus, some steps aren’t totally clear. However, I am able now to get my custom module contacts to appear in prospect_lists_prospects If I can get it to work I definitely post an updated walkthrough.

1 Like

Hey @pgr whoohoo! I got it working. I’ve got a set of instructions that I created and followed myself a second time that work along with the code. The original solution on sugaruk.co.uk worked in principal, there were just a lot of ambiguities and a few typographical errors in the code. Anyway I’ve worked through them all. Where is the best place to post the solution? Should I post the full solution here? Write a blog article and post a link? or is there a better place to post this solution? PS -thanks for all your help!

1 Like

You could make it a Technical blog post in our Docs site:

wow…great work…I was just about to follow that previous guide.

Please let us know when you have the write-up posted…

Sorry, bit of a dummy question, how do I add a technical blog? There doesn’t seem to be any “add new post” button. Apologies if this is a silly question, just never added one of those before.

So, one small hitch, I’ve got it working all the way up to the email queue. Then I can’t get it to clear the queue. Everything looks good. I am getting one error

Mon Oct 5 22:58:25 2020 [15146][1][FATAL] Cannot find bean file for module: prospectlists

When the campaign is created. Hmmm, I’m going to post the instructions here and see if you guys can see anything.

How to Add Campaign/Target List Support for a Custom Module (contacts)
Adapted from: http://web.archive.org/web/20140825230331/http:/sugaruk.co.uk/blog/how-add-campaigntarget-list-support-custom-person-module-sugarcrm

Before you start:

  1. Create One to Many relationship between your custom module and “Activities” module

  2. Create a One to Many relationship between your custom module and “Emails” module

In the code replace{module} with the name of your custom module. When you navigate to custom/modules/{module} the module name will be the name of the folder.

Step 1:
Add a custom list view for your custom module (custom/modules/{MODULE}/views/view.list.php)

You may have to create the files and directories.

<?php
require_once(‘include/MVC/View/views/view.list.php’);
class {MODULE}ViewList extends ViewList
{
public function preDisplay()
{
parent::preDisplay();
$this->lv->targetList = true;
}
}
?>

Step 2:
Create extended vardef for prospect list → custom module relationship (custom/extension/modules/{MODULE}Ext/Vardefs/prospect_list_{MODULE}.php

<?php
$dictionary["{MODULE}"][“relationships”][“prospect_list_{MODULE}”] = array (
‘lhs_module’ => ‘ProspectLists’,
‘lhs_table’ => ‘prospect_lists’,
‘lhs_key’ => ‘id’,
‘rhs_module’ => ‘{MODULE}’,
‘rhs_table’ => ‘{MODULE_TABLE}’,
‘rhs_key’ => ‘id’,
‘relationship_type’ => ‘many-to-many’,
‘join_table’ => ‘prospect_lists_prospects’,
‘join_key_lhs’ => ‘prospect_list_id’,
‘join_key_rhs’ => ‘related_id’,
‘relationship_role_column’ => ‘related_type’,
‘relationship_role_column_value’ => ‘{MODULE}’
);

$dictionary["{MODULE}"][“fields”][“prospect_lists”] = array (
‘name’ => ‘prospect_lists’,
‘type’ => ‘link’,
‘relationship’ => ‘prospect_list_{MODULE}’,
‘source’ => ‘non-db’
);
?>

Step 3:
Create a subpanel definition to show the prospect list subpanel on your custom module (custom/extension/modules/{MODULE}/Ext/Layoutdefs/ProspectListSubpanel.php)

<?php
$layout_defs["{MODULE}"][“subpanel_setup”][“prospect_lists”] = array (
‘order’ => 10,
‘sort_by’ => ‘name’,
‘sort_order’ => ‘asc’,
‘module’ => ‘ProspectLists’,
‘subpanel_name’ => ‘default’,
‘get_subpanel_data’ => ‘prospect_lists’,
‘title_key’ => ‘LBL_PROSPECT_LISTS_SUBPANEL_TITLE’,
‘top_buttons’ => array(
array(‘widget_class’ => ‘SubPanelTopButtonQuickCreate’),
array(‘widget_class’=>‘SubPanelTopSelectButton’,‘mode’=>‘MultiSelect’),
),
);
?>

Step 4:
Create a subpanel def for your custom module on the prospect list detailview(custom/extension/modules/ProspectLists/Ext/Layoutdefs/prospect_lists_{MODULE}.php
<?php
$layout_defs[“ProspectLists”][“subpanel_setup”]["{MODULE}"] = array ( //module name in lowercase
‘order’ => 10,
‘sort_by’ => ‘name’,
‘sort_order’ => ‘asc’,
‘module’ => ‘{MODULE}’,
‘subpanel_name’ => ‘ForProspectLists’,
‘get_subpanel_data’ => ‘{MODULE}’,//lowercase!!
‘title_key’ => ‘LBL_{MODULE}_SUBPANEL_TITLE’,
‘top_buttons’ => array(
array(‘widget_class’ => ‘SubPanelTopButtonQuickCreate’),
array(‘widget_class’=>‘SubPanelTopSelectButton’,‘mode’=>‘MultiSelect’),
),
);
?>

Step 5:
Create a vardef relationship field extension in custom/extensions/modules/ProspectLists/Ext/Vardefs/custom.php

<?php
$dictionary[‘ProspectList’][‘fields’][’{MODULE}’] =array ( //module name in lowercase
‘name’ => ‘{MODULE}’,//lowercase!!
‘type’ => ‘link’,
‘relationship’ => ‘prospect_list_{MODULE}’,
‘source’=>‘non-db’,
);
?>

Step 6:
Create subpanel metadata – Copy modules/{MODULE}/metadata/subpanels/default.php then rename and copy to: custom/modules/{MODULE}/metadata/subpanels/ForProspectLists.php

Step 7:
Edit modules/EmailMan/EmailMan.php around line 665 add:

$this->ref_email->load_relationship(’{MODULE_EMAILS_REL_NAME’);

You must have a relationship between your custom module and the emails module. You can find the name of the of relationship by looking in custom/Extension/modules/Emails/Ext/Vardefs/{MODULE}_activities_emails.php at the “name” property.

Around Line 689 Add:

case ‘{MODULE}’:
$rel_name="{MODULE_EMAILS_REL_NAME}";
break;

Don’t Forget to do a Repair and Rebuild

Can you get the stack trace for this? To see where it’s being called from (probably from QueueCampaign.php)

About the technical blog post - it’s just another page in the wiki-style docs site. So the instructions are here:

You can start with an existing page and edit the markdown. I can help you as you go along.

Hey @pgr. I added the document to the blog (I think??)

Also, I’ve narrowed down the problem. The error logs are not helpful. I don’t think that error I noted has to do with this issue. However, when I look in the Database at the email queue (emailman). I can see that the only on difference between a record that works (ie: contacts) and one that doesn’t (my freelancers custom module) is the relate_type. In fact, if I change the relate type in the database directly to “Contacts”, then it sends no problem. So I’m thinking in emailman.php I might have to add cases for the custom module. (PS - I have no idea what I’m doing, I’m just guessing LOL). There are bunch of instances where it references IF related_type=“Contacts” or “Prospects”, etc. I’m guessing I have to add a case for fre_freelancers in all these instances. Anyway, it’s definitely the related_type that’s stopping it from sending.

Yes, I saw your docs contribution! Cool :cool:, thanks!

But yeah, it might not be too easy to get this ultimately working. All those SELECTs will need to be tuned…

I’m going to give it a try. It looks like there are about 5-6 places to add in support for the custom module in emailman.php Hopefully, I can just follow the pattern of the contacts, targets, and leads. I’ll give it a shot and see what happens.

1 Like

Hello,

Is this solution is worked for you?

I am stuck at “EmailTemplateParser”.

Thats as far as I got. I could never get it to work. I was hoping someone could help get it over the finish line.