ReferenceError: camform is not defined

Hi!

I’ve realized that everytime that I load a task, the browser console displays the following error:

ReferenceError: camForm is not defined

The error points to the first reference of camForm in the form loaded by the task. For example, this is part of the form attached to the initial task:

<form role="form">
<script src="../../../../contratos/scripts/separ.js"></script>
<script cam-script type="text/javascript">
	camForm.on('form-loaded', function() {
		camForm.variableManager.fetchVariable('id');
		camForm.variableManager.fetchVariable('nombre');
		camForm.variableManager.fetchVariable('fecha');
	});

In this case, the error is thrown in the line with the camForm.on event handler. However, despite the error, the form seems to work fine. What is causing the error?

Thanks in advance,

Why is an error thrown?
You set the type of the form to text/javascript. This causes the browser to evaluate the script as soon as it is loaded, outside of the camunda context. Here, camForm is not defined and the script fails. Set it to text/FormScript to avoid that.

Why does it still work?
Because it is labeled as cam-script it is picked up by tasklist and executed in the Camunda context. Here, camForm is defined.

To sum it up: your script is executed twice, but the first execution fails :slight_smile:

1 Like

Hi! You’re right, I changed the script type to text/form-script and the error disappeared. Originally, it was this way, but I changed it to text/javascript so the Eclipse IDE could highlight the code as Javascript instead of displaying it as standard text.

Thanks!