You are viewing limited content. For full access, please sign in.

Question

Question

Forms - How in the world do you access Process Variables

asked on December 3, 2020

I can't access any of the variables listed as Process Variables for anything.

With the exception of Text above field where I can see there are Process Variables available they never show up when I go to use them in a Calculation or Field rule. How can you even use these variables if you can never access them in any logical condition?

0 0

Replies

replied on December 3, 2020 Show version history

Process Variables are most commonly used within the Process Designer layer, where they are readily accessible to use in conditional statements.

To use a Process Variable within a form layout, create a field and set its Default value to the desired Process Variable like so:

Make the field Read-only if desired.

This creates a Field you can use for Field Rules and a Field Variable you can use for Calculations.

Field Rules:

Calculations:

0 0
replied on December 3, 2020 Show version history

I tried everything including what you have posted here without any success.

From what I can tell Default Value is only ever used if (and only if) the field's variable has never been touched. As soon as that field has ever had a value, even if it was only for a split second, Default Value is ignored.

For example, I created 2 fields.

Current Step Name (with a Default Value)

Current Step Name Output

Then I created a javascript function on form load, that would copy what was in Current Step Name to Current Step Name Output. Then instantly clear the Current Step Name field this way Default Value wouldn't be ignored.

When the form was viewed by the next user, Current Step Name was empty, even though a Default Value was set.

This is why I wanted to access the variable with a calculation, since a calculation does not fall under these rules. If I say the field is =Step Name then it will always be equal to the current step name.

 

Edit: Maybe I am not clearing it properly? I am using .val('') to clear it but maybe that is setting the value to blank instead of null?

0 0
replied on December 4, 2020

Try adding .val('').change() instead of just .val('')

In my experience, when you change a value with .val('') alone it doesn't always trigger all of the necessary event handlers.

Another option, which I use more frequently for stuff like this, is to hide the field using field rules and set it to Ignore the data; that way it won't ever save anything and you don't need to worry about clearing it out at all.

0 0
replied on December 4, 2020 Show version history

Ah, the second option does work! I did not know that javascript could access a field removed by field rules, I thought they were actually removed from the form.

I still need the function to copy the value, but I added a field rule so that when my output field is not empty it hides the current task name field and ignores the data.

Even when I move to the next task, javascript can still access the field even though it is hidden right away, and the field gets updated with the new task name.

Thank you! This way I can use the system variables instead of scraping the browser for the task name (which I am always afraid will break across many many forms in future updates)

0 0
replied on December 4, 2020

It's hard to say for sure, but it almost sounds like you could do the second part with formulas/calculations instead of custom JavaScript too.

For example, if you set your "output" field to something like =Current_Step_Field it should update for every new step now that the step field will update properly.

0 0
replied on December 4, 2020

For some reason the calculation = does not work that way. It always equals "Start". Not sure what calculations is doing? The field certainly does not equal start, on the user task "Test". But yet this javascript, which is essentially making the 2 fields equal, works.

So something is crazy with calculations. How javascript is getting a different value than calc from the same field is anyone's guess.

  let step = $('.CurrentStep input').val();
  $('.CurrentStepOutput input').val(step).change();

 

0 0
replied on December 4, 2020

Just to confirm, you're calculation is setting the "output" field equal to the variable associated with your hidden step field right?

It might be that the population of the default value isn't triggering the calculation update so it still displays the value from the previous step.

Maybe try keeping the calculation, but trigger $('.CurrentStep input').change() as part of the document ready event.

0 0
replied on December 4, 2020

Ah but then I would be using both javascript and calc when I could just use javascript. I don't want to spread out the systems involved in getting the current step anymore than necessary. It needs to be comprehensible and easy to maintain.

Ideally calc might be easier to catch, but certainly not both calc and javascript methods.

Also, once in awhile calculations can cause a hard submission failure just because a calculation failed to run. If javascript ever fails to read the step for any reason, the worst case is the wrong fields will be shown and it can be corrected.

0 0
replied on December 4, 2020 Show version history

I get you, I was just suggesting that as a way to test if that was actually the issue. Sometimes JavaScript really is the best way to do what you need to do.

 

A tip for avoiding those hard submission failures is to make sure you're calculations never get stuck with unhandled values; in my experience the most common cause is that the calculation is looking for a value that is nonexistent or invalid.

For example =IF(Variable<>"",FORMULA(Variable...),"") will check to make the the field is not empty before attempting to use it in the "formula" piece.

Best comparison I can think of is checking for null/undefined before attempting to utilize a variable in a JavaScript function, or checking a value to avoid dividing by zero, etc.

1 0
replied on December 4, 2020

Got it! The calculation language is so foreign to me. It is like a programming challenge where you can't touch the enter key and can't use a console.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.