Hi,
Use case : let's say I want to update the "description" field with the word "Hello" for Contacts.
1 - Create your script like this and put it on your web server, for example in modules/Contacts/workflows/MyCustomClassName.php :
`
/* +**************************
class MyCustomClassName
{
function myCustomMethod(Vtiger_Record_Model $recordModel)
{
$recordModel->set('description', 'Hello');
$recordModel->setHandlerExceptions(['disableWorkflow' => true]);
$recordModel->save();
}
}
`
2 - Register your custom function #10667 where myCustomMethod is the method name and MyCustomClassName is the function name.
3 - Create/Activate a workflow
That's it, it should work either for updating a single records, mass edit or execution schedule.
Here's another example : let's say I want to update a custom field which count the number of related records.
class MyCustomClassName
{
function myCustomMethod(Vtiger_Record_Model $recordModel)
{
$relatedModuleName = 'Replace_With_Related_Module_Name';
$relationListView = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);
$count = $relationListView->getRelatedEntriesCount();
$recordModel->set('replace_with_your_custom_field_name', $count);
$recordModel->setHandlerExceptions(['disableWorkflow' => true]);
$recordModel->save();
}
Hi,
Thanks for Your examples. I have question - in second example workflow will calculate all related records. Can I define custom value - fo example if checkbox Status is TRUE - so, it will calculate this related record, if FALSE - go to next record ?
@IgorRSU yes
@vovpff but how? Create a new function like getRelationQuery() in modules/Vtiger/models/RelationListView.php ?
@IgorRSU by applying conditions before updating records
@vovpff when creating workflow in system?
@IgorRSU no. You need programmer for this. You need to write some custom function for workflow mechanism and put there some conditions to update only related records what you need instead all related records.
Most helpful comment
Here's another example : let's say I want to update a custom field which count the number of related records.
class MyCustomClassName
{
function myCustomMethod(Vtiger_Record_Model $recordModel)
{