Obtain Activity Instance Variables via Web Rest Api6.2.2

We are currently evaluating version 6.2.2 Bonitasoft Community Edition with Tomcat on Ubuntu.

Is it possible to retrieve Data Variables that are linked to a specific activity/task in the Case?

This feature seemed to be available in version 5 of the Rest api, but I cannot find an equivalent in version 6.

If this api is not available, is there a recommended workaround?

Thanks in advance.

 

 

Hi mgb777,

After browsing the open source code (https://github.com/bonitasoft/bonita-web/tree/master/rest-api/rest-api-server/src/main/java/org/bonitasoft/web/rest/server/api/bpm), I believe this is not yet available.

A possible workaround would be to instantiate a new case, which would be made of an automatic task that would call through apiaccessor the processAPI updateActivityInstanceVariables or any equivalent method.

Another solution would be to consider contributing through a pull request

I suspect the reason there is not “cart blance” access to an activities variables is for security reasons.

I mean if REST were able to dump all activities and all process variables it would be invaluable to someone who wanted to “follow” the data.

I noticed, as did you, that all REST calls have to refer to an existing variable and, as a first line of defense, this is as good as any, if you don’t know the variable name then you won’t be able to get the data.

This is a good time to think of expansion capabilities to BonitaSoft. For example a Data Dictionary that stores all variables in a process, where they are used, co-defined etc. in a database for your own company records etc. This database could then be interrogated by a REST program to get the specific variables one by one for a specific case.

Some of this is already in subscription versions, the documenting of processes for example.

To shortcut the process though, you could do this:

Make a copy of your process from studioInstallDirectory\workspace\default\diagrams - DO NOT USE THE ORIGINAL in-case you make a mistake. e.g processCompanyVacations.proc

Open your processCompanyVacations.proc in notepad++ (if using windows, an excellent text editor) and do a CNTRL-F to find. Find String “<data” (without quotes) and click Find all in Current document. This will give you a list of all variables in the current process.

Copy from the Find results page and edit down to a list that you can now add to your REST processor, you are looking for the name field. If you also need the field type then look for the associated datatype (which is another XML node).

I think you know what happens next :slight_smile:

List processVariables = ["var1", "var2", etc.] for(String processVariable : processVariables){ REST call to get activityVariable or caseVariable //do your processing }

That should do what you want. This is a dreadful shortcut. The proper way would be to read the executing process definition, save the variable list and then execute the REST call, this way if a process changes you will always have the real data.

With this shortcut you will have to regenerate the Data Dictionary List each and every publication time.

Hope this sort of helps,
regards

Hi,
Did you make it ? I’m looking for a way to do it as well.
thanks.

We decided to write our own rest api, which was built using the bonita-client engine api.

http://documentation.bonitasoft.com/javadoc/api/6.2/index.html?overview-tree.html

This allowed us to use the updateActivityInstanceVariables api call, as mentioned in the first answer.
Regards, Mark

hi i wanted to know wahat does this api do void updateActivityInstanceVariables(List operations,
long activityInstanceId,
Map<String,Serializable> expressionContexts)
throws UpdateException
can u tell me the inputs wat us the list of operation and map expression context

Hi, all

In Bonita 6.5.1 isn’t still a REST call for this?
I mean getting the name and value of the activity/task variables.
I’ve been searching but doesn’t seem to exist.

Thanks

Thanks Sean for your answer!
I really appreciate the time you took to write down your very clear post!

That truly is a dreadful shortcut but maybe one that must be traversed.

Maybe you can see this comment with more doubts that I have:
http://community.bonitasoft.com/groups/usage-operation-6x/get-initial-processs-variables-rest#comment-38967

Your answer on this thread kind off answered that question as-well but maybe you want to add something.

Thanks, yeah dreadful, but sometimes needs must…

I do have a observation though, this article is about Obtaining the process variables, the article you pointed at is Getting the process variables, though it goes on to talk about Setting process variables.

Are you wanting to only get process variables, or as I now think, are you thinking of starting a process case and setting the variables for execution?

The way I believe this works is

Start a process case
Set the case variables
Execute the first task
Set more case variables (if required)
Execute the second task
etc.

I had a look at the Create your first project with the Web REST API and Maven page for this.

This is pretty much how the online system works as well,

You start a process but until the first screen is Submitted, no variables are created, only on submit does the case really start and the first task sets variables.

regards
Seán

Hi Sean,

I do have a observation though, this article is about Obtaining the process variables, the article you pointed at is Getting the process variables, though it goes on to talk about Setting process variables.

I’ll clarify what I was aiming for.
In BOS 5.9.x and 5.10.x we had the following REST call that returned the data fields of a process definition, or by other words, get the process variables of a not launched process.
With this functionality one could adapt behaviors to meet the requirements of launching a process. Say, for example, that the flow of a process was modified by a variable defined at the creation of the process.

/ API / queryDefinitionAPI / getProcessDataFields / {processDefinitionUUID} Returns the set of dataField definitions defined within the given processDefinition UUID.

With the above call, the process variables would be known prior to the launch and was possible to use the call below with the variables to launch a process:

/ API / runtimeAPI / instantiateProcessWithVariables / {uuid} Creates an instance of the specified process with the added variable map and start the execution.

On BOS 6.5.x it’s possible to launch a process with variables:

http://10.0.70.50:9090/bonita/API/bpm/case POST Payload: {"processDefinitionId": 7270959141455656205, "variables": [{"name": "name", "value": "John"}, {"name": "email", "value": "email@email.com"} ]} Content-Type: application/json

And is possible to get the variables from a already started case/process with:

http://10.0.70.50:9090/bonita/API/bpm/caseVariable?p=0&c=100&f=case_id%3d32 GET Content-Type: application/json

What I’m unable to, is to get the variables of a existing, exposed and enabled process prior to launch a instance of it.

So it’s funny to see that it’s possible to get the variables of a started case but isn’t possible to get the variables of an existing task without the massive workaround that you mentioned on your post.
Your suggested workaround is valid to solve also the situation I described on the text above.

I actually made two questions on the post of the other thread and maybe that confused you.
The first and related to the other thread was the one I talked about on text above. And I hope I clarified the issue for you.

I then made another question that was almost offtopic regarding the other thread context. I still don’t know how to do it.

Another question, do you know the Rest call for setting more than one case/process variable after being started using only one Rest call?

Best Regards,
Makrea