0 votes
3.3k views
in Javascript API by (270 points)
Hi,

I want to update an exposed process variable for an instance from a service during the process flow using javascript in IBM BPM.

I fetched the details using "tw.system.currentProcessInstance.businessData.get(mykey)"

I tried updating using the same system api - tw.system.currentProcessInstance.businessData.put(key,value).

But this seems to be not working and it doesnt update the process variable.

I am using IBM BAW v21. Is there any alternative for this ?

Thanks

1 Answer

0 votes
by (30.6k points)

tw.system.currentProcessInstance.businessData is a read-only view of the searchable business data of the instance. The put() call only changes the JavaScript map in memory of the script, nothing is written back to the instance, so the variable never changes. There are three working ways to change a process variable of a running instance in BAW v21.

1. From inside the flow (the normal way) - a variable of a BPD changes only through the data mapping of its own activities. In the service that runs as an activity, write to tw.local.xxx and map that output variable back to the process variable on the activity's Data Mapping tab. If a script task of the BPD itself runs, tw.local is the process variable set:

// script task inside the BPD: tw.local.* are the BPD variables
tw.local.order.status = "APPROVED";
tw.local.order.approvedOn = new Date();

2. From outside the flow, with the REST API (any BPM 8.5.x / BAW 20+ server). The classic Process REST resource sets variables of a running instance by name - the body is a JSON object {"variableName": value}; the value of a business object is its JSON representation:

PUT /rest/bpm/wle/v1/process/{piid}/variables
Content-Type: application/json
BPMCSRFToken: <token from POST /rest/bpm/wle/v1/system/login>

{ "order": { "status": "APPROVED", "approvedOn": "2024-06-07T10:00:00Z" }, "comment": "set by operations" }

You can call that from a server-side service with BPMRESTRequest (see the answer to question 3127 on this site) or from any client. On BAW 21 you can also use the Process REST v2 resource POST /bpm/processes/{id} with set_data when it is listed in the instance's allowed actions.

3. Exposed business data (search index) only - if what you want is the value shown in Process Portal searches, the value is updated automatically whenever the underlying variable is changed by the flow; nothing has to be "put".

Why businessData.put looks like it works: it is a plain java.util.Map copy handed to the script - the JS API documents it as data for reading (get, iteration). Anything that has to survive the script must go through mapping or the REST API.

References

Related questions

0 votes
1 answer 1.4k views
0 votes
1 answer 2.9k views
0 votes
1 answer 1.3k views
0 votes
1 answer 2.1k views
0 votes
1 answer 2.6k views
0 votes
1 answer 1.7k views
0 votes
1 answer 3.4k views
0 votes
2 answers 10.2k views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...