Share ideas, ask questions, and get feedback about developing for ProcessMaker

Moderators: ArturoRobles, ArturoRobles

Forum rules: Please post new questions under "Developing processes & programming" for ProcessMaker 2 or 3.
By akshaydange
#786797
Hi Everyone,

I have two task in my process. In first task i used grid for candidate information like name, address, contact & selected status. And second task for candidate details for single candidate whose selected status is "selected". In my process if 3 candidates are selected then 3 task will be generated for 3 selected candidates. Please give me suggestion. My code is as follow
Code: Select all
$taskId     = '72278902357eb74f0b755a0019340838';
$processId = @@PROCESS; 

$grid = @=form1_grid;

$rows = count($grid);
for ($i=1; $i <= $rows; $i++) {
	
	$name = $grid[$i]["name"];
	$contact_no = $grid[$i]["contact_no"];
	$status = $grid[$i]["status"];
	
	if($status == 'Selected'){
		
		$caseUID = PMFNewCase($processId, $taskId);
		@=candidate_name = $name;
		@=contact_no = $contact_no;
		
	if ($caseUID) {
      
      executeQuery("UPDATE APPLICATION SET APP_STATUS='TO_DO' WHERE APP_UID='$caseUID'");
      
    }
	}
}
User avatar
By amosbatto
#786800
There are two ways to handle this. Either create two separate processes or use a variable number of parallel tasks. If you want a variable number of tasks, see: http://wiki.processmaker.com/3.0/Trigge ... r_of_Times


If you want two separate processes, then in the first process you have all the candidates in the grid and you select the ones you want. In the second process you do something with each candidate, so your trigger code needs to create a new case for each candidate, like this:
Code: Select all
$taskId     = '72278902357eb74f0b755a0019340838'; //set to ID of starting task in the second process
$processId = 'XXXXXXXXXXXXXXXXXXXXXXX'; //set to ID of the second process
$grid = @=form1_grid;

$rows = count($grid);
for ($i=1; $i <= $rows; $i++) {
   
   $name = $grid[$i]["name"];
   $contact_no = $grid[$i]["contact_no"];
   $status = $grid[$i]["status"];
   
   if($status == 'Selected'){
      $aVars = array(
           "name"     => $name,
           "contact_no" => $contact_no
       );
       $newCaseId = PMFNewCase($processId, @@USER_LOGGED, $taskId, $aVars);  
       if ($newCaseId) {
          executeQuery("UPDATE APPLICATION SET APP_STATUS='TO_DO' WHERE APP_UID='$newCaseId'");
       }
   }
}
User avatar
By amosbatto
#787315
You probably have an empty row at the end of your grid.

You can do this if you always have an empty row at end:
Code: Select all
for ($i=1; $i < $rows; $i++) {


But it is better to check for empty value in one of your grid fields and if empty, then don't generate case.
REST API Question

I am currently looking at developing a portlet for[…]

Everybody wants to be famous, but nobody wants to […]

Hi, I attached a sample config file, Please check […]

Error clicking on Participated

Hi, I attached a sample config file, Please check […]