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
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.
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!
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:
Create One to Many relationship between your custom module and âActivitiesâ module
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 , 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.
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.
Hey,
I came across this post a bit late, but I wanted to share my experience with adding target list support for a custom module. I ended up using a similar solution, and it worked well for me.
One key point is that itâs important to implement the EmailInterface
in your custom module. Without this, the cron job will fail in the EmailTemplateParser
constructor, which expects an object implementing EmailInterface
.
If you correctly add relationships between your custom module and both the Emails
and ProspectLists
modules, there should be no issues.
Regarding the case
clause in the request, it doesnât seem very useful if your custom module extends the Person
class. Iâd recommend checking out the EmailMan.php
file, specifically the get_list_view_data()
function, for a better approach.
Awesome! you could share your solution here step by step, so it will help others in the future.
Iâd still love to know a solution for this! If you can be a little more specific as to what I can add/do differently to what Iâve done so far that would be great!
I checked the differences step by step :
Step 1: I donât know what itâs for, but I donât think itâs necessary.
Step 2:
You did :
$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}',
);
Hereâs my solution :
$dictionary['prospect_lists_prospects']['relationships']['prospect_list_{MODULE_NAME}'] = array(
'lhs_module' => 'ProspectLists',
'lhs_table' => 'prospect_lists',
'lhs_key' => 'id',
'rhs_module' => '{MODULE_NAME}',
'rhs_table' => '{TABLE_MODULE_NAME}',
'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_NAME}',
);
You can check out the native SuiteCRM metadata in the prospect_lists_prospectsMetaData.php
file.
This is the correct way to populate the prospect_lists_prospects
table with the real relation between your custom module and the ProspectLists
module.
Then you did :
$dictionary["{MODULE}"]["fields"]["prospect_lists"] = array(
'name' => 'prospect_lists',
'type' => 'link',
'relationship' => 'prospect_list_{MODULE}',
'source' => 'non-db',
);
My solution :
$dictionary["{MODULE_NAME}"]["fields"]['prospect_lists'] = array(
'name' => 'prospect_lists',
'type' => 'link',
'relationship' => 'prospect_list_{TABLE_MODULE_NAME}',
'module' => 'ProspectLists',
'source' => 'non-db',
'vname' => 'LBL_PROSPECT_LIST',
);
I donât really know how SuiteCRM handle this, but I think the âmoduleâ key is important for creating the relation.
Step 3: I havenât created a subpanel definition for my custom module yet.
Step 4: Okay, I just used âdefaultâ for âsubpanel_name.â
Step 5: Okay, but {MODULE}
in the relationship must be in lowercase. (itâs the table module name)
Step 6: I didnât do that because default.php does the job for my case.
Step 7: Okay, but there is another case used for email saving. Try to add it here too.
For now, with my solution, the target list is working in the Campaigns module, and emails are being sent. However, I am experiencing some issues with the subpanel and the graph in the campaign results. I can provide an update here once I investigate this case, if youâre interestedâŚ
If you still have any issues, let me know; I might be able to helpâŚ