Use camunda variables in javascript

Hi everybody,

I have a problem…

I want to use my camunda variables (for example ‘processID’ or other variables from Modelling) in javascript. With:

<script cam-script type="text/form-script">
	var variableManager = camForm.variableManager;


	camForm.on('form-loaded', function() {
  		// fetch the variable 'customVariable'
  		variableManager.fetchVariable('value');
	});

	camForm.on('variables-fetched', function() {
    	// access to all process variables after the form has loaded
		$scope.value = variableManager.variable('value');
    });
</script>

I can load them and print to console. But I want to use them in an other javascript file. Is that ppssible?

Thanks and beste reguards,
Fredo

Hey @Fredo
can you explain what you are trying to achieve ? Maybe we find a solution together.

Hey @felix-mueller ,

in my process I have variables, for example for a euro value. Depending on this amount other values have to be loaded by REST. I did not manage to read this process instance dependent value.

Is that understandable so far ?

best regards,
Fredero

Hey @Fredo

with the code you mentioned above you can get the variables from Camunda.
Once the variables are fetched, in the callback function you can define what should happen:

camForm.on('variables-fetched', function() {
    	// access to all process variables after the form has loaded
		$scope.value = variableManager.variable('value');

        // add your rest call here.....
         if ($scope.value === 'eur') {
         }
    });

Makes sense?

Best
Felix

1 Like

Hey @felix-mueller,

thank you!

That’s what I’ve been thinking about. I just wanted to do the if-query in another JS file, thought that would be nicer. But this works in my case!

Thanks
Best Regards,
Fredo

1 Like