1.

螣螝, I will try to describe the problem, sorry for my English.
When a field is updated with workflow for the first time (on creating a record), it seems that was updated on the screen, but the record is not stored in the database. If you modify the record and then save again all is good.
Please help!
anything in the logs?
(only in create record execution) The error occurs because the variable $isNew is not set to false before call the record model function $recordModel->set($fieldName, $fieldValue) and then $recordModel->getPreviousValue() is always empty.
https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/modules/com_vtiger_workflow/tasks/VTUpdateFieldsTask.php#L84-L87
https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/modules/Vtiger/models/Module.php#L226
https://github.com/YetiForceCompany/YetiForceCRM/blob/developer/modules/Vtiger/models/Record.php#L70-L77
in the file modules/com_vtiger_workflow/tasks/VTUpdateFieldsTask.php override the function do task with this:
public function doTask($recordModel)
{
$util = new VTWorkflowUtils();
$util->adminUser();
$moduleName = $recordModel->getModuleName();
$moduleModel = $recordModel->getModule();
$recordId = $recordModel->getId();
$moduleFields = $moduleModel->getFields();
$fieldValueMapping = [];
if (!empty($this->field_value_mapping)) {
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
}
if (!empty($fieldValueMapping) && count($fieldValueMapping) > 0) {
$isNew = $recordModel->isNew();
if ($isNew) {
$recordModel->isNew = false;
}
$util->loggedInUser();
foreach ($fieldValueMapping as $fieldInfo) {
$fieldName = $fieldInfo['fieldname'];
$fieldValueType = $fieldInfo['valuetype'];
$fieldValue = trim($fieldInfo['value']);
$fieldInstance = $moduleFields[$fieldName];
if ($fieldValueType == 'expression') {
require_once 'modules/com_vtiger_workflow/expression_engine/include.php';
$parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));
$expression = $parser->expression();
$exprEvaluater = new VTFieldExpressionEvaluater($expression);
$fieldValue = $exprEvaluater->evaluate($recordModel);
//for Product Unit Price value converted with based product currency
if ($fieldInstance && $fieldInstance->getFieldDataType() == 'currency' && $fieldName == 'unit_price') {
$fieldValue = $this->calculateProductUnitPrice($fieldValue);
}
} elseif ($fieldValueType !== 'fieldname') {
if (preg_match('/([^:]+):boolean$/', $fieldValue, $match)) {
$fieldValue = $match[1];
if ($fieldValue == 'true') {
$fieldValue = '1';
} else {
$fieldValue = '0';
}
}
//for Product Unit Price value converted with based product currency
if ($fieldInstance && $fieldInstance->getFieldDataType() == 'currency' && $fieldName == 'unit_price') {
$fieldValue = $this->calculateProductUnitPrice($fieldValue);
}
}
$recordModel->set($fieldName, decode_html($fieldValue));
}
// Added as Mass Edit triggers workflow and date and currency fields are set to user format
// When saving the information in database saveentity API should convert to database format
// and save it. But it converts in database format only if that date & currency fields are
// changed(massedit) other wise they wont be converted thereby changing the values in user
// format, CRMEntity.php line 474 has the login to check wheather to convert to database format
// For workflows update field tasks is deleted all the lineitems.
// $focus->isLineItemUpdate = false;
$recordModel->setHandlerExceptions(['disableWorkflow' => true]);
$recordModel->save();
if ($isNew) {
$recordModel->isNew = true;
}
// Reverting back the action name as there can be some dependencies on this.
$util->revertUser();
}
$util->revertUser();
}
Thank you @nic86.
It works like a charm!!!
Most helpful comment
Thank you @nic86.
It works like a charm!!!