Where can I find documentation on how to ābuildā a value for a workflow action?
I would like to find full documentationā¦ but the case in hand is trying to Set the āNameā of the record to the āNameā of the related record āUserā and some text concatenated " Vacation".
I saw one example where they said we could say something like now - 8 hoursā¦ but without documentation, I donāt know what the possibilities are.
https://suitecrm.com/index.php?option=com_kunena&view=topic&catid=4&id=2007&Itemid=1136#8675
Thanks,
Drew
Will
31 August 2014 20:38
2
Hi Drew,
This would require custom coding and is not something available in the out-of-the-box workflow.
Thanks,
Will.
Iām posting this here for my own benefit as much as othersā¦ because I need to get back to this file to make the required edits. This seems so needed that Iām wondering, however, if someone else already has code that does this.
Iām going to need to edit /public_html/avant/modules/AOW_Actions/actions/actionCreateRecord.php.
The function āset_recordā simply need some way to know that I want to set the value to a value in another field rather than a constantā¦ I then will make it smart enough to concatenate it in some way. Iām not sure if Iāll do something simple like a ā+ā, or if Iāll make it able to process PHP code which would be a really nice something like āfield1.field2ā or functions like all caps, proper case, etc.
function set_record(SugarBean $record, SugarBean $bean, $params = array(), $in_save = false){
global $app_list_strings, $timedate;
$record_vardefs = $record->getFieldDefinitions();
if(isset($params['field'])){
foreach($params['field'] as $key => $field){
if($field == '') continue;
switch($params['value_type'][$key]) {
case 'Field':
if($params['value'][$key] == '') continue;
$data = $bean->field_defs[$params['value'][$key]];
if($data['type'] == 'relate' && isset($data['id_name'])) {
$params['value'][$key] = $data['id_name'];
}
$value = $bean->$params['value'][$key];
break;
case 'Date':
$dformat = 'Y-m-d H:i:s';
if($record_vardefs[$field]['type'] == 'date') $dformat = 'Y-m-d';
switch($params['value'][$key][3]) {
case 'business_hours';
if(file_exists('modules/AOBH_BusinessHours/AOBH_BusinessHours.php')){
require_once('modules/AOBH_BusinessHours/AOBH_BusinessHours.php');
$businessHours = new AOBH_BusinessHours();
$dateToUse = $params['value'][$key][0];
$sign = $params['value'][$key][1];
$amount = $params['value'][$key][2];
if($sign != "plus"){
$amount = 0-$amount;
}
if($dateToUse == "now"){
$value = $businessHours->addBusinessHours($amount);
}else if($dateToUse == "field"){
$dateToUse = $params['field'][$key];
$value = $businessHours->addBusinessHours($amount, $timedate->fromDb($bean->$dateToUse));
}else{
$value = $businessHours->addBusinessHours($amount, $timedate->fromDb($bean->$dateToUse));
}
$value = $timedate->asDb( $value );
break;
}
$params['value'][$key][3] = 'hours';
//No business hours module found - fall through.
default:
if($params['value'][$key][0] == 'now'){
$date = gmdate($dformat);
} else if($params['value'][$key][0] == 'field'){
$date = $record->fetched_row[$params['field'][$key]];
} else {
$date = $bean->fetched_row[$params['value'][$key][0]];
}
if($params['value'][$key][1] != 'now'){
$value = date($dformat, strtotime($date . ' '.$app_list_strings['aow_date_operator'][$params['value'][$key][1]].$params['value'][$key][2].' '.$params['value'][$key][3]));
} else {
$value = date($dformat, strtotime($date));
}
break;
}
break;
Case 'Round_Robin':
Case 'Least_Busy':
Case 'Random':
switch($params['value'][$key][0]) {
Case 'security_group':
if(file_exists('modules/SecurityGroups/SecurityGroup.php')){
require_once('modules/SecurityGroups/SecurityGroup.php');
$security_group = new SecurityGroup();
$security_group->retrieve($params['value'][$key][1]);
$group_users = $security_group->get_linked_beans( 'users','User');
$users = array();
$r_users = array();
if($params['value'][$key][2] != ''){
require_once('modules/ACLRoles/ACLRole.php');
$role = new ACLRole();
$role->retrieve($params['value'][$key][2]);
$role_users = $role->get_linked_beans( 'users','User');
foreach($role_users as $role_user){
$r_users[$role_user->id] = $role_user->name;
}
}
foreach($group_users as $group_user){
if($params['value'][$key][2] != '' && !isset($r_users[$group_user->id])){
continue;
}
$users[$group_user->id] = $group_user->name;
}
break;
}
//No Security Group module found - fall through.
Case 'role':
require_once('modules/ACLRoles/ACLRole.php');
$role = new ACLRole();
$role->retrieve($params['value'][$key][2]);
$role_users = $role->get_linked_beans( 'users','User');
$users = array();
foreach($role_users as $role_user){
$users[$role_user->id] = $role_user->name;
}
break;
Case 'all':
default:
$users = get_user_array(false);
break;
}
// format the users array
$users = array_values(array_flip($users));
if(empty($users)){
$value = '';
}else if (sizeof($users) == 1) {
$value = $users[0];
} else {
switch($params['value_type'][$key]) {
Case 'Round_Robin':
$value = getRoundRobinUser($users, $this->id);
break;
Case 'Least_Busy':
$user_id = 'assigned_user_id';
if(isset($record_vardefs[$field]['id_name']) && $record_vardefs[$field]['id_name'] != ''){
$user_id = $record_vardefs[$field]['id_name'];
}
$value = getLeastBusyUser($users, $user_id, $record);
break;
Case 'Random':
default:
shuffle($users);
$value = $users[0];
break;
}
}
setLastUser($value, $this->id);
break;
case 'Value':
default:
$value = $params['value'][$key];
break;
}
if($record_vardefs[$field]['type'] == 'relate' && isset($record_vardefs[$field]['id_name'])) {
$field = $record_vardefs[$field]['id_name'];
}
$record->$field = $value;
}
}
$bean_processed = isset($record->processed) ? $record->processed : false;
if($in_save){
global $current_user;
$record->processed = true;
$check_notify = $record->assigned_user_id != $current_user->id && $record->assigned_user_id != $record->fetched_row['assigned_user_id'];
}
else $check_notify = $record->assigned_user_id != $record->fetched_row['assigned_user_id'];
$record->process_save_dates =false;
$record->new_with_id = false;
$record->save($check_notify);
$record->processed = $bean_processed;
}
sieberta