How do I change the value of a variable

how do I change the value of a variable in the cam-script directive. know to create after i click complete is the following code

	camForm.on ('submit',function () { 
			type: 'String',
			value: $('#numInfo').val(),
			isDirty: true

Hi @MarceloCP,
Use below code to change the value of a process variable

camForm.variableManager.variable('<PROCESS_VARIABLE_NAME>').value = <NEW_VALUE>

Thanks for the answer but the value is not changed, I did the test on the console displaying the value that is in the variable and appears right but if I try to assign a new value as your script does not work, what could be wrong?

camForm.on (‘submit’,function () {
var newValue = document.getElementById(‘situation’).value
camForm.variableManager.variable(‘new_situation’).value = newValue

Hi @MarceloCP,

The value of the process variable won’t change until the form is submitted or more specifically until the first point of wait state is reached.

If you want to change the value of the process variable while the form is opened then, you could invoke the rest API.

when I click on complete task wouldn’t be submitting the form? But in my drawing it loops and returns to the same task but then would it be a new task or not? I will test moving on to the next task in the stream to see if the variable value changes.

Yes, it would be a new task instance and value should be changed… did you monitor the variable from cockpit app?

Wonderful, now it worked carrying the variable before, thank you very much. Not wanting to explore much how I can display this value in the form in a label, as it is a loop and back to the same form if I put cam-variable-name in an input says that this variable already exists in the form.

Hi @MarceloCP,

You can do it as below

camForm.on('form-loaded', function() {
  // this callback is executed *before* the variables are loaded from the server.
  // if we declare a variable here, its value will be fetched as well

camForm.on('variables-fetched', function() {
  // this callback is executed *after* the variables have been fetched from the server
  var variableValue = camForm.variableManager.variableValue('customVariable');
  $( '#my-container', camForm.formElement).textContent(variableValue);

You can get the variable’s value either using