Well, using this we cannot get complex objects, only simple type variables and lists.
Simple type variables are returned as is (boolean as boolean, date as date, etc.).
Lists are returned as serialized XML string, so we must deserialize them into a variable with type list of object.
I use this code to get process level variables:
tw.local.name (String) input paramer: the name of the variable to return
tw.local.values (ANY*) output parameter: the returned list if the variable is a list of object
tw.local.value (ANY) output parameter: the returned value of the variable if the variable isn't a list
var pi = tw.system.findProcessInstanceByID(tw.system.currentProcessInstanceID);
var value = pi.businessData.get(
tw.local.name);
if (value != null) {
if (/^<\s*variable\s*type\s*=\s*".*\[\]"\s*>.*/.test(value)) {
// List in XML
tw.local.values = tw.system.serializer.fromXml("" + value);
} else {
// Single value
if (typeof value === "string") {
tw.local.value = "" + value;
} else {
tw.local.value = value;
}
}
}
------------------------------
Laszlo
------------------------------
Original Message:
Sent: Thu February 11, 2021 10:46 AM
From: Andrew Paier
Subject: How to get instance variable values within a human task after it is started?
Excellent find! I vaguely remember that perhaps in the past there were some problems with those calls. This might be bad memory on my part of a bug that has since been fixed. I want to say that there was a problem retrieving complex/nested types that way. Can you share if you are pulling Business Objects or individual data?
------------------------------
Andrew Paier
Original Message:
Sent: Thu February 11, 2021 03:46 AM
From: Laszlo Kertesz
Subject: How to get instance variable values within a human task after it is started?
Hi Andrew, and All!
Finally I found the solution using JS API:
- Get the process instance by its ID
var pi = tw.system.findProcessInstanceByID(instanceId); - Get a business data of the process instance by its name
var value = pi.businessData.get("variableName");
More info can be found here: https://www.ibm.com/support/pages/how-access-process-instance-data
I tested and it returns the current value of the process variables, so it returns the new values right after a call of tw.system.updateCurrentInstanceVariablesByCurrentTaskOwner(...);
------------------------------
Laszlo
Original Message:
Sent: Thu February 11, 2021 02:30 AM
From: Laszlo Kertesz
Subject: How to get instance variable values within a human task after it is started?
Good Idea, thanks Andrew!
------------------------------
Laszlo
Original Message:
Sent: Wed February 10, 2021 04:59 PM
From: Andrew Paier
Subject: How to get instance variable values within a human task after it is started?
The instance variables can be read using the ReST API. I'd assume they pick up on the changes made via that JS call (but I've not tested that)
------------------------------
Andrew PaierAndrew Paier
Original Message:
Sent: Wed February 10, 2021 03:55 PM
From: Laszlo Kertesz
Subject: How to get instance variable values within a human task after it is started?
Hi All,
We can set process instance variables within a task using tw.system.updateCurrentInstanceVariablesByCurrentTaskOwner. But how can we get their values from code when the human task is running yet? I mean, not as Input parameter, but the actual values from code while the task is running, or postponed but later continued? Is it possible at all?
Thx,
------------------------------
Laszlo
------------------------------