Workflow send two email

Hi all,
I have a workflow in a custom module that sends an email on saving (even if I edit). The problem is that I also have an aftersave hook on this module. Thus, the email arrives double.
Can I avoid it in any way?
Thanks a lot!

@2di7
Can you show the logichook?

Hi,
This is the structure of the logichook, I need it to update fields in another custom module.

    <?php
    	if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    	
    	class logic_hooks_class    
    	{
    		function after_save_method ($bean, $event, $arguments)
    		{
    			if (!isset($bean->ignore_update_c) || $bean->ignore_update_c === false)
    			{

    					
    //my query
    					
    					$bean->ignore_update_c = true;
    					$bean->save();
    					}
    			}
    		}
    	}
    ?>

But the problem is the save that launches the workflow again.

@2di7

It’s standard mistake.
You should use logichook before_save then you will remove check for endless cycle and function $bean->save(). The second message generate with $bean->save() function.

2 Likes

Hi and thanks.
The problem is that I can’t make my update query in before_save because $GLOBALS ['db'] and $db don’t seem to work.

In after_save I did this:

$db = DBManagerFactory::getInstance();
					
			$appr = $bean->appr_c;
					
			if ($appr!='in_attesa') {
				$query = "SELECT bol_bol_anagrafica_bol_bol_cond_2_c.bol_bol_988fdizioni_idb FROM bol_bol_anagrafica_bol_bol_cond_2_c WHERE bol_bol_f71dgrafica_ida='" . $bean->id ."'";
				$result = $db->query($query);    
				while($row = $db->fetchByAssoc($result)){  
					$bean->$db->query("UPDATE bol_bol_cond_cstm SET approvazione_c=" . $appr. " WHERE id_c='".$row['bol_bol_988fdizioni_idb']."' AND bol_bol_cond_cstm.id_c IN (SELECT bol_bol_cond.id FROM bol_bol_cond WHERE bol_bol_cond.deleted=0 AND bol_bol_cond.name=2021)"); } 
			}

Thanks for any suggestions.