JBPM Kie-wb process variables

1,113 views
Skip to first unread message

Oleg Fedorov

unread,
Oct 18, 2016, 11:35:16 AM10/18/16
to jBPM Usage
Hi!

For two days i can't understand how i can get access to my process variables with data objec type (java class).
I have a data object : 

package org.spbpu.lib.recordmanipulationproj;

/**
 * This class was automatically generated by the data modeler tool.
 */

@javax.persistence.Entity
public class ActDO implements java.io.Serializable
{

   static final long serialVersionUID = 1L;

   @javax.persistence.GeneratedValue(strategy = javax.persistence.GenerationType.AUTO, generator = "ACTDO_ID_GENERATOR")
   @javax.persistence.SequenceGenerator(name = "ACTDO_ID_GENERATOR", sequenceName = "ACTDO_ID_SEQ")
   private java.lang.Long id;

   @javax.persistence.OneToMany(cascade = { javax.persistence.CascadeType.ALL }, fetch = javax.persistence.FetchType.EAGER)
   @org.kie.api.definition.type.Label("Заявки")
   private java.util.List<org.spbpu.lib.recordmanipulationproj.RecordDO> records;

   @org.kie.api.definition.type.Label("Дата")
   private java.util.Date dateDoc;

   @org.kie.api.definition.type.Label(value = "\u041D\u043E\u043C\u0435\u0440")
   private java.lang.String num;

   public ActDO()
   {
   }

   public java.lang.Long getId()
   {
      return this.id;
   }

   public void setId(java.lang.Long id)
   {
      this.id = id;
   }

   public java.util.List<org.spbpu.lib.recordmanipulationproj.RecordDO> getRecords()
   {
      return this.records;
   }

   public void setRecords(
         java.util.List<org.spbpu.lib.recordmanipulationproj.RecordDO> records)
   {
      this.records = records;
   }

   public java.util.Date getDateDoc()
   {
      return this.dateDoc;
   }

   public void setDateDoc(java.util.Date dateDoc)
   {
      this.dateDoc = dateDoc;
   }

   public java.lang.String getNum()
   {
      return this.num;
   }

   public void setNum(java.lang.String num)
   {
      this.num = num;
   }

   public ActDO(java.lang.Long id,
         java.util.List<org.spbpu.lib.recordmanipulationproj.RecordDO> records,
         java.util.Date dateDoc, java.lang.String num)
   {
      this.id = id;
      this.records = records;
      this.dateDoc = dateDoc;
      this.num = num;
   }

}

I define a variable of this type of process. 



And in script task have a code:


String tmpstr = kcontext.getVariable("teststr");
tmpstr = tmpstr + " ! END ! ";
kcontext.setVariable("teststr", tmpstr);

org.spbpu.lib.recordmanipulationproj.ActDO testObj = (org.spbpu.lib.recordmanipulationproj.ActDO)kcontext.getVariable("_actBP");
  
System.out.println("12394485584");
System.out.println(kcontext.getVariable("teststr"));
System.out.println(kcontext.getVariable("_actBP/zct"));


But сompilation fails. When using JAVA lang for script task erro is : rocess Compilation error Type mismatch: cannot convert from Object to String.
MVEL said me that it can't find this class ActDo. when i tried to use only string type i had no problems.

So, I have a question. What's wrong with my code?

Exuce for my English style. I am just learning.

Maciej Swiderski

unread,
Oct 21, 2016, 2:26:37 AM10/21/16
to Oleg Fedorov, jBPM Usage
What version of jBPM and Java are you running on?

Don't see anything wrong at first sight, so will try to run it today ...

Maciej

--
You received this message because you are subscribed to the Google Groups "jBPM Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-usage+unsubscribe@googlegroups.com.
To post to this group, send email to jbpm-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-usage/7000d4e2-325e-4dc2-9470-a62cf21fd306%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oleg Fedorov

unread,
Oct 21, 2016, 2:58:44 AM10/21/16
to jBPM Usage, oda...@gmail.com
Its JBPM 6.4.0.Final
Java 1.7

Oleg Fedorov

unread,
Oct 21, 2016, 3:12:56 AM10/21/16
to jBPM Usage, oda...@gmail.com
Hello again.

One more question:
In script task i can change language to JavaScript. But i cant find some good information about how i can use it inside a task. Could you explain me what kind of object have we got in and what kind of js we have (ES5 ?). Or maybe you can give a good link where i can read about it.

Oleg

Maciej Swiderski

unread,
Oct 21, 2016, 5:56:58 AM10/21/16
to Oleg Fedorov, jBPM Usage, oda...@gmail.com
Alright, this is the problem:
String tmpstr = kcontext.getVariable("teststr");

getVariable() returns Object so you need to cast it

Maciej

On 21.10.2016, at 08:58, Oleg Fedorov <odar...@gmail.com> wrote:

Its JBPM 6.4.0.Final
Java 1.7

--
You received this message because you are subscribed to the Google Groups "jBPM Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-usage+...@googlegroups.com.

To post to this group, send email to jbpm-...@googlegroups.com.

Maciej Swiderski

unread,
Oct 21, 2016, 5:58:01 AM10/21/16
to Oleg Fedorov, jBPM Usage, oda...@gmail.com
you have access to process variables and globals and you can use standard java script as it will be invoked by the javascript engine that comes with java.

Maciej
--
You received this message because you are subscribed to the Google Groups "jBPM Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-usage+...@googlegroups.com.

To post to this group, send email to jbpm-...@googlegroups.com.

sanket joshi

unread,
Oct 3, 2017, 3:44:48 AM10/3/17
to jBPM Usage
Hi Maciej,

Let's consider we have Data Object for example User with fields name and email of type String, and we want to retrieve name of user only.
I tried something like below in both java and javascript but it's returns null.

String usreName = kcontext.getVariable("user.name");

Is there any other simple way to do same..

Maciej Swiderski

unread,
Oct 3, 2017, 3:57:36 AM10/3/17
to sanket joshi, jBPM Usage
simply use user.getName() in the script task body or you can use expression in the data input assignments #{user.getName()}

Maciej

Sanket Joshi

unread,
Oct 3, 2017, 4:17:34 AM10/3/17
to jBPM Usage
That will be work for particular field, like in this case name only.

I have requirement where I am consuming few REST API using REST Work Item Handler.
Where all rest end point url are there in property files because it might be change in future, for example-
Now in process I just want to replace dynamic fields with actual process data.

I need name of user but in future API may request for any other field.

Maciej Swiderski

unread,
Oct 3, 2017, 4:24:27 AM10/3/17
to Sanket Joshi, jBPM Usage
use expression as I mentioned before #{user.getName()} and #{deployment.getId()}

Maciej

Sanket Joshi

unread,
Oct 3, 2017, 6:25:29 AM10/3/17
to jBPM Usage
It's working...

I just replace all dynamic field with expression suggested by you and kept my all url listed as is in side my classpath properties.
And it's working now. 

Thank you Maciej.

km

unread,
May 5, 2021, 11:01:13 AM5/5/21
to jBPM Usage
String tmpstr = kcontext.getVariable("teststr");
If same line above , if i have to cast it to string in java-script how do i achieve it?
Reply all
Reply to author
Forward
0 new messages