How to setup a Workflow to send an email to Projects > Businesses > custom_field (User list)

I just trying to figure out a way to create a Workflow in SuiteCRM for the following requirement.

In Businesses there is a custom drop-down to select ‘Account Manager’ (User list)
CRM has Projects. Projects and Businesses have one-to-one relationship.
I want to trigger an email alert to ‘Account Manager’ in Business which is linked to a Project, when Project status changed to ‘Completed’

the problem is I’m unable to setup a Workflow since ‘Account Manager’ field is not visible in Workflow mail settings (Action > Send mail > field list)
Can someone help me on this pls?

To set up workflow on the ‘Account Manager’ Field you need to add a Custom action link for sending email to the account manager on workflow action.

@jessica1 thanks for your help.
may I know how can I add Custom action link?

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.

( @jessica1 please click the pencil icon on the top-right of your post and examine my edit to your post - this way you can learn how to use the forum codes to insert strings without losing the bracket characters, and to get syntax highlighting on code listings )

Thanks for suggesting this, I will keep in mind.