6 Replies Latest reply on Apr 28, 2015 6:26 AM by Francesco Scarcella

    Setting process variable in script task using BPM standard method

    new-comer Newbie

      Hi,

      I know that you can set a process variable in the script task by doing:

      kcontext.getKnowledgeRuntime().setGlobal(name, value)

       

      but my requirement is not to use any jBPM specific in the BPMN xml, it can only be BPMN standard, so I am not sure if that is doable to set the process variable with none jBPM method.

       

      Any idea?

       

      Thanks.

       

        • 1. Re: Setting process variable in script task using BPM standard method
          Tihomir Surdilovic Master

          That is typically the responsibility of the runtime as you are changing the state of the process instance data and not its definition.

          • 2. Re: Setting process variable in script task using BPM standard method
            Maciej Swiderski Master

            jBPM nodes can define dataoutput that then are used to set process variables, for instance human task can have defined dataoutput and its assignments to achieve what you described. Don't think script task supports that and looking at your case not sure you should use it to set variable like this. Variables are set/changed based on some steps in the process or external interaction. So better is to look at what can change a variable and define it via dataoutputs.

             

            HTH

            • 3. Re: Setting process variable in script task using BPM standard method
              new-comer Newbie

              Thanks for replying.

               

              In my case, I have a few paralleled human tasks to do review job, let's say I have 3 review tasks, and the end result will be based on the 3 reviewers' feedback, for each reviewer's feedback, I use dataoutput mapping set back to one process variable, and when all 3 review task is finished, I need to base on the 3 feedbacks to decide if the job is passed review or not, the reason is that we have a  percentage, let's say 60% or higher, we think the review is OK, in this case, there will be 2 or 3 review tasks give OK. and this does not need any human involvment, only a calculation based on the result of the 3 review tasks. Based on the pass percentage, the work will be passed to next step or rejected to the work submitter.

               

              Hope it explains what I need to do.

               

              If script task should not be used for this scenario, do you have a better suggestion how to do it?

               

              Thanks.

              • 4. Re: Setting process variable in script task using BPM standard method
                Maciej Swiderski Master

                yes, this what I was assuming is your use case. So I would suggest to use a domain specific service that will be responsible for calculated based on data inputs and then use dataoutputs to set the result of calculation as process variable

                 

                HTH

                • 5. Re: Setting process variable in script task using BPM standard method
                  Francesco Scarcella Newbie

                  Excuse me Maciej,

                  what do you want to say with domain specific service?


                  i would set a process variable to a constant value.

                  the idea is:

                   

                  start -> set process variable to a constant -> human task (now the process is bolocked waiting the human event; before giving the input i would get the variable value from java code) -> end

                   

                  I tried with script task without success and then with a business rule task with an empty drl file (i setted only the input and output assigment, to set a constant value i use input assigment equal to "myString" then with output mapping i defined an output with the same name of input and mapped that to my process variable).

                  This two way don't work for me, infact java side when i recover the processVariables i obtain a map correctly but there aren't any values associated to the key.

                   

                  from java code i wrote:

                   

                  ...

                  ProcessInstance processInstance = processService.getProcessInstance(Long.parseLong(instanceId));

                  log.info("The process considered has id : " + processInstance.getProcessId());

                  ProcessDefinition process = runtimeDataService.getProcessById(processInstance.getProcessId());

                  log.info("Recovering process variables");

                  String value = process.getProcessVariables().get("variableName");

                  log.info("Process variables recovered: " + value); // INFO  [it.marche.siform2.service.BaseBeanService] (default task-18) Process variables recovered: String

                  ...

                   

                   

                   

                   

                   


                   

                  • 6. Re: Setting process variable in script task using BPM standard method
                    Francesco Scarcella Newbie

                    Probably i solved my problem,

                    this is my process that has a variable named inputValues

                    myProcess.png

                     

                    in script Task Set variables:

                     

                    kcontext.setVariable("inputValues","approva|rigetta");


                    the branch of the exclusive gateway


                    approvato branch = return  KieFunctions.equalsTo(esito, "approva");

                    rigettato branch = return  KieFunctions.equalsTo(esito, "rigetta");

                     

                    in java code

                     

                    ProcessInstance processInstance = processService.getProcessInstance(Long.parseLong(instanceId));

                    log.info("The process considered has id : " + processInstance.getProcessId());

                     

                    log.info("Recovering process variables for the process");

                    String value = (String) processService.getProcessInstanceVariable(Long.parseLong(instanceId), INPUT_VALUES); //INPUT_VALUES is a constant equal to inputValues

                    log.info("######## variable value = " + value.toString()); //approva|rigetta

                     

                    now i can split the value and obtain the command that my process would receive. In this manner i can create generic businessProcess and is the process to tell me which command pass. When i complete the humanTask i pass the command (approva or rigetta) as paramMap and humanTask onexit pass the paramater then gateway decide about that param

                     

                    What do you think about this solution?

                    1 of 1 people found this helpful