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