Fetching Variables a second time in embedded form

Hi,

we have a process where we store some variables containing PDF files. In our embedded form we load a JSON that is containing the variable names that have the PDF files. Like

{“pdfVariables”:[{“metainfo”: “infoA”, “name”: “variableA”},{“metainfo”: “infoB”, “name”: “variableB”}]}.

Now we want to have Downloadbuttons for each variable that is containing a PDF. We want to fetch the variable when the button is clicked. But we get the following error message:

"Error: “Illegal State: cannot call fetchVariable(), variables already fetched.”

Does somebody has a idea how to solve this?

Kind regards,
Enno

Hi @enno,

When you call fetchVariable(), you simply mark that variable to be fetched from the back-end. But the actual fetch from the back-end would take place during the second phase of the form life-cycle.

In the second phase, a request is made to the server to gather the values of the variables declared in the variable manager.

Whenever you need to fetch a value for a variable from the back-end, make sure to mark it to be fetched before the second phase.

“In form-loaded event listener”

 camForm.on('form-loaded', function() {
      variableManager.fetchVariable('customVariable');
    });

The error you get is because the second phase is already completed which means fetch is already done.

Hi, Hassang! I have a similar problem and unfortunately, camForm.on(‘form-loaded’) listener doesn’t help me because I didn’t know the variable name during loading form I would get the variable name later when the user press a button and run $http.post which creates the variable but how can I fetch it now?

Hi, Enno! Did you solve this problem ?