Page 1 of 1

SOLVED Workflow Extract Process Variable Value

PostPosted:Wed Sep 02, 2015 2:11 am
by alexwgordon
Hi Guys,

I'm trying to create a workflow that assigns tasks to users and I'm stuck at a part with the "Select" field (dropdown) in the form element. Basically the user who is assigned the original task will then pass the task off to someone else using the Select field (dropdown). How can I extract the value that the user selects from that dropdown and pass it into a decision node?

In the workflow backend, it's showing the value of the variable as this:
Code: Select all
{label=, name=value, width=150px, height=25px, readonly=false, type=simple, value=alex, data=, optionsData=, options=[{label=okmAdmin, value=okmAdmin, selected=false}, {label=reviewer, value=reviewer, selected=false}, {label=alex, value=alex, selected=true}], validators=[], table=, optionsQuery=, suggestion=, class=}
I want to get the value of "value" (which is "alex" in this case).

Any advice would be amazing! Thank you guys!

SOLVED Workflow Extract Process Variable Value

PostPosted:Thu Sep 03, 2015 6:09 pm
by alexwgordon
Okay in case anyone else is new to Java and didn't get this, this is what I ended up doing. It was crazy simple, so apologies to everyone!
Code: Select all
package com.openkm.workflow.Approval2;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
import com.openkm.bean.form.Select;

public class setNewReviewer implements ActionHandler {
    private static final long serialVersionUID = 1L;
    public String aktor;
 
    @Override
    public void execute(ExecutionContext executionContext) throws Exception {
    	Select useVar = (Select) executionContext.getContextInstance().getVariable("username");
    	
    	if (useVar != null) {
    		String useVal = useVar.getValue();  //returns string
    		executionContext.getContextInstance().setVariable("aktor", useVal);
		} else {
			executionContext.getContextInstance().setVariable("aktor", null);
		}
    }
}

Re: SOLVED Workflow Extract Process Variable Value

PostPosted:Fri Sep 04, 2015 6:54 am
by jllort
Also consider:
Code: Select all
String value = "";

// It's for select of type simple, for multiple should do minimal changed ( remove break, etc. )
for (Option option : userVar.getOptions()) {
   if (option.isSelected()) {
   	value = option.getValue();
   	break;
   }
}

Re: SOLVED Workflow Extract Process Variable Value

PostPosted:Fri Sep 04, 2015 5:37 pm
by alexwgordon
Also works! Thanks jllort!