orange office

The Blog

Our thoughts on technology

GX5 Blogs

Catch up on the latest technology news from our in house writers.

Using SugarCRMs campaign module with a custom module.

Using SugarCRMs campaign module with a custom module.

This post will show you an easy and sure fire way to get your custom person module working with SugarCRMs campaign and target list module. This has been tested in Sugar version 7.2

Please note that you will need to have a access to the SugarCRM files to be able to complete this tutorial successfully.

In this tutorial, please replace modulename with the name of your module. Also replace moduletable with the name of the module table in the database. 

  1. Create the relationship between your custom module and the Target List module. Head over to Administration >> Studio >> Target Lists. Click on Relationships and create a new Many to Many relationship with your custom module.
    This should allow you to add your module to a target list but unfortunately it adds it to a seperate database table than the Campaigns module searches for.
  2. The new relationship info will be stored in SugarInstallFolder >> custom >> metadata >> prospectlists_modulenameMetadata.php. With your favourite IDE or Editor browse to this file and open it. Edit the file so it looks something like the code below. Replace modulename with the name of your module.
    $dictionary["prospectlists_modulename_1"] = array (
      'true_relationship_type' => 'many-to-many',
      'from_studio' => true,
      'relationships' => 
      array (
        'prospectlists_modulename_1' => 
        array (
          'lhs_module' => 'ProspectLists',
          'lhs_table' => 'prospect_lists',
          'lhs_key' => 'id',
          'rhs_module' => 'modulename',
          'rhs_table' => 'modulename',
          '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' => 'modulename'
        ),
      ),
    );
  3. By this point, you should now be able to add your module records into a target list and it will be useable by the campaign module for sending out messages. The next step is to record this data in SugarCRM table. Open SugarInstallFolder >> modules >> EmailMan. 
  4. Allow the module to be included in the select list. Copy line 84 and paste it on line 85. Replace 'Prospects' with the name of your module. It should look like this
    WHEN 'modulename' THEN ".$this->db->concat('moduletable', array('first_name', 'last_name'), ' ')."
  5. Copy line 91 and paste it on line 92. Again replace 'Prospects' with the name of your module. It should look like this.
    LEFT JOIN moduletable ON moduletable.id = $this->table_name.related_id and $this->table_name.related_type ='modulename'
  6. Copy line 141 and paste it on line 142. Replace 'Prospects' with the name of your module. It should look like this.
    WHEN 'modulename' THEN ".$this->db->concat('moduletable', array('first_name', 'last_name'), ' ').
  7. Copy line 150 and paste it on line 151. Replace 'Prospects' with the name of your module. It should look like this.
    LEFT JOIN moduletable ON moduletable.id = $this->table_name.related_id and $this->table_name.related_type ='modulename'
  8. Copy line 190 and paste it on line 191. Replace 'Prospects' with the name of your module. It should look like this.
    WHEN 'modulename' THEN ".$this->db->concat('moduletable', array('first_name', 'last_name'), ' ')."
  9. Copy line 199 and paste it on line 200. Replace 'Prospects' with the name of your module. It should look like this.
    LEFT JOIN moduletable ON moduletable.id = $this->table_name.related_id and $this->table_name.related_type ='modulename'
  10. On line 391, enter the following code to have the emails saved against the module record.
    $this->ref_email->load_relationship('relwithemail');
    You should replace "relwithemail" with the name of the relationship between your module and the email module.
  11. On lines 417 to 419, add a new case statement to handle the custom module. Your code should look like this. Remember to replace "relwithemail" just as you did in step 10.
    case 'modulename':
                        $rel_name="relwithemail";
                        break;
  12. Repeat step 11 on lines 488 to 490.

You are done. Your module is now linked to the Campaigns module and you can begin sending different types of campaigns. Emails sent via the Campaigns module will also be recorded against your module records.

Learn how to display 'Add to Target Lists' for custom modules.

For SugarCRM consulting and information, please contact us using our contact form or request a call back

Accelerate your site with Cloudflare
Display 'Add to Target List' for custom module on ...

Related Posts