Campaign Workflow

Hi,

I’d like to setup a workflow to create a follow-up call to each lead/contact associated with a campaign. The calls should be created five days after the start date of the campaign is reached. I don’t realy see how this one-to-many relations of the campaign can be catched to create multiple calls from a workflow related to the campaign module. Any ideas?

Martin

If a Workflow is “On scheduler”, and “All records”, it will loop through every record in a module. but you might have difficulty gathering all the information you need from related modules, etc.

An alternative is to try Workflows that cover a single record, it might be simpler. For example, you might try catching the event of the new email created for a Lead when the campaign is sent, and adding it there at that moment. The call would be immediately created, but with a planned date for 5 days from now.

When creating calls from Workflows, make sure you add every required field, otherwise it won’t create anything.

Here’s a sample call creation WF that works for me:

1 Like

I built a workflow based on created emails. Unfortunately a campaign creates exactly one email record in the database that is somehow related to all the batch of sent emails. But these records are stored in different tables of the database.

At the end my workflow created one call that was associated with the campaign and not with any contact/lead.

I googled a whole lot for creating calls from campaigns. I’d bet this is a very common workflow for a lot of companies, but it seems not to be. I’d be happy to find a way to do a mass creation of calls at least manually of any contact list. Is that possible at any chance?

Regards,
Martin

Yes I felt this shortcoming in a project I help out with for a non-profit. Creating calls automatically would be a nice feature to have.

I made for that project some very basic code to create calls, can you handle some PHP or do you need to stick to solutions from the user interface only?

I have no fear of php :wink:

Ok, here you go. This loops through a Target List creating Calls for each Contact (only Contacts, but it’s easy to extend to other types of records).

In custom/modules/ProspectLists/controller.php


<?php
class CustomProspectListsController extends SugarController
{
    public function action_createcallpassedids() {
        if ( !empty($_REQUEST['uid']) ) {
            $recordIds = explode(',',$_REQUEST['uid']);
            foreach ( $recordIds as $recordId ) {
                $list = SugarModule::get($_REQUEST['module'])->loadBean();
                $list->retrieve($recordId);
                echo "Sent Record ID {$list->id}, name "; //.$bean->get_summary_text()."";



                        if($list->load_relationship('contacts')) { // Get related Contacts
                            $contacts = $list->contacts->getBeans();
                            if(!empty($contacts)) {
                                foreach($contacts as $contact) { // Loop through Contacts
                                    if($contact->load_relationship('calls')) {
                                        $call = BeanFactory::newBean('Calls'); // Create
                                        $call->name = $list->description . $contact->name;
                                        $bean->direction = "Outbound";
                                        $bean->status = "Planner";
                                        $bean->duration_hours = "0";
                                        $bean->duration_minutes = "10";
                                        //$bean->date_start = "2016-07-25";
                                        $bean->parent_type = "Contacts";
                                        $bean->parent_id = $contact;
                                        $call->assigned_user_id = $list->assigned_user_id;
                                        $call->save();
                                        $contact->calls->add($call->id); // Relate Task to Contact
                                        $contact->save();
                                    }
                                }
                            }
                        }

In custom/modules/ProspectLists/views/view-list.php


<?php
require_once('include/MVC/View/views/view.list.php');
class CustomProspectListsViewList extends ViewList

{
    /**
     * @see ViewList::preDisplay()
     */
    public function preDisplay()
    {
        parent::preDisplay();
        $this->lv->actionsMenuExtraItems[] = $this->buildMyMenuItem();
    }
    /**
     * @return string HTML
     */
    protected function buildMyMenuItem()
    {
        global $app_strings;
    
        return <<<EOHTML
<a class="menuItem" style="width: 150px;" href="#" onmouseover='hiliteItem(this,"yes");' 
        onmouseout='unhiliteItem(this);' 
        onclick="sugarListView.get_checks();
        if(sugarListView.get_checks_count() &lt; 1) {
            alert('{$app_strings['LBL_LISTVIEW_NO_SELECTED']}');
            return false;
        }
        document.MassUpdate.action.value='createcallpassedids';
        document.MassUpdate.submit();">Create calls</a>

EOHTML;
    }
}
  • it’s a good strategy try to get this example working exactly as it is, before attempting any changes;

  • known issue: this handles multiple Target Lists at once, but doesn’t handle more than one page of them in the list. So if you select more than 20 Target Lists, only the first 20 will get processed. But normally the idea is for people to use this with a single Target List (which has as many people as needed inside it).

  • this is ugly, doesn’t show a proper view

1 Like