From 83e4ee23bed94016756c899c954568cb098b9964 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Tue, 16 Sep 2025 16:41:57 -0400 Subject: [PATCH 1/2] Add test for process variable assignment with literal ID in TaskAssignmentByVariableTest --- .../Api/TaskAssignmentByVariableTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/Feature/Api/TaskAssignmentByVariableTest.php b/tests/Feature/Api/TaskAssignmentByVariableTest.php index 2fb5d8d6d3..1d62397894 100644 --- a/tests/Feature/Api/TaskAssignmentByVariableTest.php +++ b/tests/Feature/Api/TaskAssignmentByVariableTest.php @@ -250,6 +250,26 @@ public function testProcessVariableAssignmentWithObjectVariable() $this->assertEquals($users->first()->id, $task->user_id); } + public function testProcessVariableAssignmentWithLiteralId() + { + // Create users of a group and a user without group + $user = User::factory()->create(['status'=>'ACTIVE']); + $group = $this->createGroup(5); + $process = $this->createProcess('process_variable', $user->id, $group->id, '', false); + + // The first assignment should be to user (is the first created user) + $response = $this->startTestProcess($process, []); + $requestId = $response['id']; + $task = ProcessRequestToken::where(['process_request_id' => $requestId, 'status' => 'ACTIVE'])->firstOrFail(); + $this->assertEquals($user->id, $task->user_id); + + // The second assignment should be to the first user of the created group + $response = $this->startTestProcess($process, []); + $requestId = $response['id']; + $task = ProcessRequestToken::where(['process_request_id' => $requestId, 'status' => 'ACTIVE'])->firstOrFail(); + $this->assertEquals($group->users->first()->id, $task->user_id); + } + /** * Creates a process in which the assignment of the first task is configured based on the parameters of this function * From 160bc7e87d4b27c18e635df764cd4fa49881de78 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Tue, 16 Sep 2025 16:43:40 -0400 Subject: [PATCH 2/2] Implement evaluation of BPMN FEEL expressions for Process Variable assignments. --- ProcessMaker/Models/Process.php | 4 ++-- helpers.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ProcessMaker/Models/Process.php b/ProcessMaker/Models/Process.php index ebeb70bc0c..1a7b5da4b6 100644 --- a/ProcessMaker/Models/Process.php +++ b/ProcessMaker/Models/Process.php @@ -773,8 +773,8 @@ private function getNextUserFromProcessVariable($activity, $token) $dataManager = new DataManager(); $instanceData = $dataManager->getData($token); - $assignedUsers = $usersVariable ? Arr::get($instanceData, $usersVariable) : []; - $assignedGroups = $groupsVariable ? Arr::get($instanceData, $groupsVariable) : []; + $assignedUsers = $usersVariable ? feelExpression($usersVariable, $instanceData) : []; + $assignedGroups = $groupsVariable ? feelExpression($groupsVariable, $instanceData) : []; if (!is_array($assignedUsers)) { $assignedUsers = [$assignedUsers]; diff --git a/helpers.php b/helpers.php index 203e2322c8..1611f418f4 100644 --- a/helpers.php +++ b/helpers.php @@ -3,6 +3,7 @@ use Illuminate\Support\Facades\Auth; use Laravel\Horizon\Repositories\RedisJobRepository; use ProcessMaker\Events\MarkArtisanCachesAsInvalid; +use ProcessMaker\Models\FormalExpression; use ProcessMaker\Models\Setting; use ProcessMaker\SanitizeHelper; use ProcessMaker\Support\JsonOptimizer; @@ -359,3 +360,20 @@ function json_optimize_decode(string $json, bool $assoc = false, int $depth = 51 return JsonOptimizer::decode($json, $assoc, $depth, $options); } } + +if (!function_exists('feelExpression')) { + /** + * Evaluate a BPMN FEEL expression + * + * @param string $expression + * @param array $data + * @return mixed + */ + function feelExpression(string $expression, array $data) + { + $formalExp = new FormalExpression(); + $formalExp->setLanguage('FEEL'); + $formalExp->setBody($expression); + return $formalExp($data); + } +}