Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderators: ArturoRobles, ArturoRobles

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By Logeswari
#788367
Hi,
I would like to achieve the following scenario through grid:
1. I have 2 tasks in my process, namely Receptionist and Managers.
2. The receptionist will update the late comers details in grid.
3. The grid consist of 10 records, if the receptionist submits the form the grid rows have to be divided based on the condition and sent to the managers.
Code: Select all
Grid in Receptionist task
-----------------------------------------------------------------------------------
Emplyee Name	  Date	        Reason	       Team	        Managers
-----------------------------------------------------------------------------------
Durga	         10/01/2017	Late coming     RND	        James
John	                 10/01/2017	Cab Late	       Business	Shanthi
Durai	                 10/01/2017	Late coming     Admin	James
-----------------------------------------------------------------------------------
4. I would like to send the each record separately to the Manager (2) those who metioned in the grid
5. For example
1. Manager : James -> Should receive only “Durga and Durai” records not the whole record.
Code: Select all
-----------------------------------------------------------------------------------
Emplyee Name	  Date	        Reason	       Team	        Managers
-----------------------------------------------------------------------------------
Durga	         10/01/2017	Late coming     RND	        James
Durai	                 10/01/2017	Late coming     Admin	James
-----------------------------------------------------------------------------------
2. Manager: Shanthi -> Should receive only “John” record not the whole record.
Code: Select all
-----------------------------------------------------------------------------------
Emplyee Name	  Date	        Reason	       Team	        Managers
-----------------------------------------------------------------------------------
John	                 10/01/2017	Cab Late	       Business	Shanthi
-----------------------------------------------------------------------------------
3. If the Managers updates any thing in the grid, that has to be affected in the receptionist form.

How to achieve this functionality? I have tried my level best i couldn’t achieve. Is there any way to achieve it. Please help me.

Thanks in advance.

Regards,
Logeswari
User avatar
By amosbatto
#788407
Let's say that the first grid will be associated with the variable receptionistGrid and it has fields with the IDs:
"id", "employeeName", "date", "reason", "team", "managers"
(you need to add the hidden "id" field because you need to be able to update rows between the two grids)

Then you have another grid associated with the variable managersGrid, which has the same fields in it as the first grid.

Then, create a trigger which is fired after the first DynaForm with the receptionistGrid, which inserts IDs in the grid:
Code: Select all
if (isset(@=receptionistGrid) and is_array(@=receptionistGrid)) {
   $g = new G():
   for ($i = 1; $i <= count(@=receptionistGrid); $i++) {
      if (empty(@=receptionistGrid[$i]['id'])) {
         @=receptionistGrid[$i]['id'] = $g->generateUniqueID();
      }
   }   
} 
Then, create a second trigger which is fired before the second DynaForm with the managerGrid, which will filter its content according the logged-in user:
Code: Select all
if (isset(@=receptionistGrid) and is_array(@=receptionistGrid)) {
   @=managerGrid = array();
   $i = 1;    //counter of rows in managerGrid
   foreach (@=receptionistGrid as $aRow) {
      if (trim($aRow['managers']) == @@USR_USERNAME) {
         @=managerGrid[$i] = $aRow;
         $i++;
      }
   }
}
Then, create a third trigger which is fired after the second DynaForm with the managerGrid, which will update the records in the receptionistGrid:
Code: Select all
if (isset(@=managerGrid) and is_array(@=managerGrid)) {
   foreach (@=managerGrid as $aManagerRow) {
      //search for same row in receptionistGrid and replace it:
      for ($i=1; $i <= count(@=receptionistGrid); $i++) {
         if (@=receptionistGrid[$i]['id'] == $managerRow['id']) {
            @=receptionistGrid[$i] = $managerRow;
            break;
         }
      }
   }      
}
You might have to debug these triggers, since I haven't tried them, but they give you an idea how to do it.

Do you want the receptionist to be able to keep editing the records while the managers are editing them or does the receptionist just need a read-only copy? For a read only copy, I suggest that you make an Output Document which has the content of the receptionistGrid and give the receptionist Process Permissions to access the Output Document. Then use this code for your third trigger:
Code: Select all
if (isset(@=managerGrid) and is_array(@=managerGrid)) {
   foreach (@=managerGrid as $aManagerRow) {
      //search for same row in receptionistGrid and replace it:
      for ($i=1; $i <= count(@=receptionistGrid); $i++) {
         if (@=receptionistGrid[$i]['id'] == $managerRow['id']) {
            @=receptionistGrid[$i] = $managerRow;
            break;
         }
      }
   }
   //update the receptionistGrid before generating an Output Document with it.
   PMFSendVariables(@@APPLICATION, array('receptionistGrid' => @=receptionistGrid));
   $outputDocId = 'XXXXXXXXXXXXXXXXXXXXX'; //set to ID of Output Document
   PMFGenerateOutputDocument($outputDocId);  
}
PS: Another way to do this is create a custom summary form to display the receptionistGrid, but there is currently a bug with Process Permissions and Summary Forms, so it recommended to use an Output Document for now.

If you need the receptionist to be able to edit the receptionistGrid while the managers are also editing the managersGrid, then you can create parallel tasks:
ParallelReceptionistTask.png
ParallelReceptionistTask.png (19.09 KiB) Viewed 1703 times
By fiqihpunya
#826411
amosbatto wrote: Wed Jan 11, 2017 12:49 pm Let's say that the first grid will be associated with the variable receptionistGrid and it has fields with the IDs:
"id", "employeeName", "date", "reason", "team", "managers"
(you need to add the hidden "id" field because you need to be able to update rows between the two grids)

Then you have another grid associated with the variable managersGrid, which has the same fields in it as the first grid.

Then, create a trigger which is fired after the first DynaForm with the receptionistGrid, which inserts IDs in the grid:
Code: Select all
if (isset(@=receptionistGrid) and is_array(@=receptionistGrid)) {
   $g = new G():
   for ($i = 1; $i <= count(@=receptionistGrid); $i++) {
      if (empty(@=receptionistGrid[$i]['id'])) {
         @=receptionistGrid[$i]['id'] = $g->generateUniqueID();
      }
   }   
} 
Then, create a second trigger which is fired before the second DynaForm with the managerGrid, which will filter its content according the logged-in user:
Code: Select all
if (isset(@=receptionistGrid) and is_array(@=receptionistGrid)) {
   @=managerGrid = array();
   $i = 1;    //counter of rows in managerGrid
   foreach (@=receptionistGrid as $aRow) {
      if (trim($aRow['managers']) == @@USR_USERNAME) {
         @=managerGrid[$i] = $aRow;
         $i++;
      }
   }
}
Then, create a third trigger which is fired after the second DynaForm with the managerGrid, which will update the records in the receptionistGrid:
Code: Select all
if (isset(@=managerGrid) and is_array(@=managerGrid)) {
   foreach (@=managerGrid as $aManagerRow) {
      //search for same row in receptionistGrid and replace it:
      for ($i=1; $i <= count(@=receptionistGrid); $i++) {
         if (@=receptionistGrid[$i]['id'] == $managerRow['id']) {
            @=receptionistGrid[$i] = $managerRow;
            break;
         }
      }
   }      
}
You might have to debug these triggers, since I haven't tried them, but they give you an idea how to do it.

Do you want the receptionist to be able to keep editing the records while the managers are editing them or does the receptionist just need a read-only copy? For a read only copy, I suggest that you make an Output Document which has the content of the receptionistGrid and give the receptionist Process Permissions to access the Output Document. Then use this code for your third trigger:
Code: Select all
if (isset(@=managerGrid) and is_array(@=managerGrid)) {
   foreach (@=managerGrid as $aManagerRow) {
      //search for same row in receptionistGrid and replace it:
      for ($i=1; $i <= count(@=receptionistGrid); $i++) {
         if (@=receptionistGrid[$i]['id'] == $managerRow['id']) {
            @=receptionistGrid[$i] = $managerRow;
            break;
         }
      }
   }
   //update the receptionistGrid before generating an Output Document with it.
   PMFSendVariables(@@APPLICATION, array('receptionistGrid' => @=receptionistGrid));
   $outputDocId = 'XXXXXXXXXXXXXXXXXXXXX'; //set to ID of Output Document
   PMFGenerateOutputDocument($outputDocId);  
}
PS: Another way to do this is create a custom summary form to display the receptionistGrid, but there is currently a bug with Process Permissions and Summary Forms, so it recommended to use an Output Document for now.

If you need the receptionist to be able to edit the receptionistGrid while the managers are also editing the managersGrid, then you can create parallel tasks:
ParallelReceptionistTask.png
hallo amosbatto, how i can update database with grid data's?
Timeout Not Sending Email

I am confused, but I have setup a self-service as[…]

Hello; In a dynaform (for example: called "Gr[…]

issue with processmaker 3.2

Ok thank you but i have more questions For exam[…]

No, there's nothing wrong in the browser network a[…]