For creating a custom action link in workflow action, you need to create action.ext.php file on below path,
<YOURCRM>custom/Extension/modules/AOW_Actions/Ext/Actions/CustomModuleActions.ext
After Creating file, add below code in your file,
Once you add code, Create actionCustomAction.php file for run action on below path,
<YOURCRM>custom/modules/AOW_Actions/actions/actionCustomAction.php
In the edit_display function, you need to write your html code which you want to show in workflow action.
Add Below Code in edit_display function for actionCustomAction.php
public function edit_display($line, SugarBean $bean = null, $params = array()){
//Get Module
$modulename = $bean->module_dir;
//URL To Notify
$urlNotifyLabel = '"'.translate('LBL_URL_NOTIFY_INFO','AOW_Actions').'"';
$parameterFields = getModuleFieldsDropdown('Accounts', '', 0);
$html .= "<fieldset>";
$html .= "<div class='ParametersContainer'>";
$html .= "<table class='tbl_action_method'>";
$html .= "<tr rowspan = '4'><td><b>Related Module Fields:</b></td></tr>";
$html .= "<tr rowspan = '4'>";
$html .= "<td><b><select option='select' name='aow_actions_param[".$line."][action_method]'>";
$html .= "<option selected='selected'>".$parameterFields."</option></select></td>";
$html .= "<td><b><select option='select' name='aow_actions_param[".$line."][action_method]'>";
$html .= "<option selected='selected'>".$parameterFields."</option></select></td>";
$html .= "</table>";
$html .= "</div>";
return $html;
}//end of function
After adding html code in edit_display function, Workflow custom action block looks like below screenshot,
After Setting Workflow, add run_action function for run action based workflow configuration.
Add below code in run_action function of actionCustomAction.php file
public function run_action(SugarBean $bean,$params = array(),$in_save = false){
$projectStatus = $bean->status;
$field = $bean->getFieldDefinition($params['related_module_name']);
$relateId = $field['id_name'];
if($projectStatus == "Completed"){
$relatedModule = BeanFactory::getBean($field['module'], $relateId);
$relatedFieldId = $relatedModule->$params['related_module_fields'];
$userBean = BeanFactory::getBean('Users', $relatedFieldId);
$email = $userBean->email1;
require_once('modules/Emails/Email.php');
require_once('include/SugarPHPMailer.php');
$emailObj = BeanFactory::newBean('Emails');
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
$mail->From = $defaults['email'];
isValidEmailAddress($mail->From);
$mail->FromName = $defaults['name'];
$mail->Subject = $emailSubject;
$mail->Body = $emailBody;
$mail->IsHTML(true);
$mail->prepForOutbound();
$mail->AddAddress($email);
$mail->Send();
}
return false;
}//end of function
After adding all the things, Create/Edit Project record based on workflow configuration and check Email you will get or not on the selected account manager email address.