2
1
0

We are evaluating if Joget can be used for our workflow requirements. 

For one of the projects we have, we need to be able to have a variable number of participants, specified at runtime by the user (through the form). 

To test this, I am tweaking the example here: Multiple Approval

But instead of having the users mapped in, I want to use the values that a user enters in through a form: 

ex: 

I would want the approvers to be bbrown, and jsmith. I vaguely know how to map to users and groups from workflow variables, but how do I get the username values in the grid to be stored into those variables in the first place? 

Details would be greatly appreciated! 

    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      Hi Stephanie,

      Sorry for late reply, let say your form grid ID is "fg_approver".

      And this is the step of jquery function:

      1. Find each row on fg_approver using find function
      2. If u notice that the row in the grid has grid-cell class, we can use it to get all row.
      3. Iterate using each function.
      4. append the result to variable "approver".

       

      	$('[name="fg_approver"]').find('table').each(function() {
      		var approver ="";			
              $(this).find('.grid-cell').each(function(){	        	      		        		
      	        	approver = approver + ';'+$(this).text();		        	        		        	
          	});
      	}
      
      

      Next set the value of "approver" variable, to the hidden field using another jquery 

      $('[name="hiddenFieldID"]').attr("value",approver);

      You can add checker inside the each function just in case the value is undefined or empty, the complete code is like this:

      $('[name="fg_Approver"]').find('table').each(function() {
      		var approver ="";			
              $(this).find('.grid-cell').each(function(){	        	
              	if ($(this).text()!==undefined && $(this).text() !=null && $(this).text() !='') {		        		        		
      	        	approver = approver + ';'+$(this).text();		        	
              	};	        		        	
          	});
      		if(approver!=''){
      			$('[name="hiddenFieldID"]').attr("value",approver);
      		}
      	}

      Set the code event to run when user click submit.

      Note: the code above is workable, but you can modify it to make it more perfect.

      Below is a jquery reference for you:

      1. Name Selector: https://api.jquery.com/attribute-contains-selector/
      2. Find Element : https://api.jquery.com/find/
      3. Each Function: http://api.jquery.com/jquery.each/

      Hope it helps

        CommentAdd your comment...
      1.  
        2
        1
        0

        What do you mean "I would want the approvers to be bbrown, and jsmith". is it both must approved first then the process run again. or just one of approver need to approve?

        If it just one (bbrown or jsmith), Usually to accomplish this kind of requirement, in the form I create a hidden field, that mapped to a workflow variable. The participant mapping, is mapped to workflow variable username.

        Then back to the form I add a custom html field, that contain a jquery that filled the hidden field each time a row is added, then seperate per username by ";".

         

        1. Stephanie

          Hi Yonathan, Can you show an example of the jquery that is used to populate the hidden field? I am having trouble getting it to run every time the row is added and accessing the hidden field to set its value. Thank you!

        CommentAdd your comment...