How to get all process variables from inside view mode (activity mode)

Hello everyone.

I hope to get information about how to pull out all process variables from inside viewer window. In my case, I want to get specific pool (process) variables, so I do following commands:

// bmpnModeler is an instance of  new Viewer
const elementRegistry = bpmnModeler.get('elementRegistry');

// Here I get the node id from the overlay which is added on top
const selectedNodeId = e.target.parentNode.parentNode.getAttribute('data-container-id');
const element = elementRegistry.get(selectedNodeId);
const processId = element.businessObject.$parent.id;

and now If I try to use this library GitHub - bpmn-io/extract-process-variables: An util for bpmn-js to extract Camunda BPM process variables from a BPMN 2.0 diagram. and do the following:

const rootElement = bpmnModeler.get('canvas').getRootElement();
const scopedVars = getVariablesForScope(processId, rootElement); 
console.log(scopedVars);

I get this kind of error: Uncaught TypeError: Cannot read properties of undefined (reading ‘$parent’) .

If I pull out all process vars:

const allVars = getProcessVariables(rootElement.businessObject);
console.log(allVars);

I get an empty array.

Packages that I’m using:

"bpmn-js": "^9.2.2",
"bpmn-js-differ": "^2.0.2",
"bpmn-js-embedded-comments": "^0.6.1",
"bpmn-js-properties-panel": "^1.2.0",
"camunda-bpmn-moddle": "^6.1.1",
"@bpmn-io/extract-process-variables": "^0.6.0",
"@bpmn-io/properties-panel": "^0.20.3",

Is there any other way to get the desired result and pull out the process variables?

image

Is there any minds on that? :slight_smile:

Note that getVariablesForScope expects a model element:

const rootElement = bpmnModeler.get('canvas').getRootElement();
const scopedVars = getVariablesForScope(processId, rootElement.businessObject);