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

Question

Question

Using Tokens in Java Scripting to get value from another form in the same process

asked on April 7, 2021 Show version history

Hi,

Is it possible to use a token {/dataset/variable} in Java Script ?

I have a process where the main process runs and then stops at a certain stage if a Sub Process has been kicked off, currently this works great, but I had to disable the "Save Draft" button. I am being asked to enable this button again.

 

This value is a Yes /  No from a drop down, Main process form has this variable (hidden) and then on the sub process form is the same variable. The variable is hidden on the Main process form and I use JS to hide (When empty or "No") or show the button to proceed to the next stage once this value is "Yes". The issue is, when the "Save Draft" button is clicked, then this value does not update and then the users can't complete the process.

 

I want to remove this field from the Main Process and use Java Script to fetch the value from the other form on the sub process once it has been completed, the main process form will re-run this Java Script on form load especially when it is saved as draft.

 

Things I have tried:

  1. Use FX Calculation to =(variable)
  2. Add JS trigger on form load to update or trigger the same field
  3. Field Rules to show this field, but it is using the same field to hide it which does not work.
  4. Use workflow to retrieve the value and then update the value which does not work on the Save Draft
  5. Looked at several posts on answers, this one is the closest I got to an answer {/_currentuser} variable not changing in the same form - Laserfiche Answers 

 

Any advice on this would be appreciated.

0 0

Replies

replied on April 7, 2021

It is not possible to access variables directly. What I do is put a hidden section at the bottom of the form, using the class "hidden" in the advanced properties of the section.

Here you can put fields/variables from other forms that users can not see but your script can see them.

0 0
replied on April 7, 2021

Hi Chad, this does not work when "Save Draft" is clicked. I can easily do this if the "Save Draft" is not used, but that causes the value not to update. As soon as I delete the draft again, then it works.

0 0
replied on April 7, 2021

So you have a starting form where your variable is first filled out and submitted. Then you have a user task form that shares the same field.

When that task is loaded the field value will be what it was on submission.

Saving a draft should never change the variable if the user can not see it to change it.

You should unhide it and see why it is changing when you save as draft.

0 0
replied on April 7, 2021

No, this variable is selected at the end of the sub process. This variable is only displayed on that form where as it is hidden on the Main Process form (also not the starting form). This process runs in parallel, it depends on the selection to complete the task. The user reaches the Main Process form where this variable is hidden way before it is done on the sub process, therefore the Save as Draft leaves all variables in a state it was before saving as draft. The only way around I can see is Java Scripting

0 0
replied on April 7, 2021

The description of a Sub-Process is this:

Sub-processes are only helpful for organizing complex processes into manageable sections.

Based on this, I don't think having or not having a sub-process changes anything with your design, only the visual representation.

Are you trying to access a variable from the future? That isn't logically possible. I am assuming the field existed on some previous submission and you want to access it's value with javascript.

To do this put the field on your form and you will see the value. If you save as draft and re-open the task, you will still see it's value. This value can be accessed with javascript at any time.

 

 

0 0
replied on April 7, 2021

This process is rather complex, that’s why it is running in parallel and a different section in a sub process. Even if it’s un-hidden, it is a different department that has to be blocked from completing the process so I’m hiding the submit button with “complete” label. 
 

Even if it is a future value, the logic works as this gets updated once the form where the button is hidden gets updated upon opening the form.

 

i just thought there would be a different way to retrieve the value using java script when it is saved as draft since this value can be used in a gateway.

 

The value will be blank on the form it is hidden, saving as draft keeps this value as blank, no matter what I try. This task gets opened or refreshed (after the sub process is complete and the drop down yes / no selection) then the value is still blank. If i do exactly the same when save as draft is not clicked or draft is deleted, then it works.

 

if you say this should work, should I open a support case instead?

0 0
replied on April 7, 2021 Show version history

"saving as draft keeps this value as blank"

This is working as intended. Why would you want a value to change when the user clicks save as draft?

I feel like the question of "Java Scripting to get value from another form in the same proccess" is throwing me off. This doesn't imply an expectation that anything changes. Just that you want to get the value from a previous submission in your process.

Sometimes it helps to create a new sandbox to simplify what your trying to do, then once understood, implement it into the complicated form process.

0 0
replied on April 7, 2021 Show version history

Sorry Chad, my intention was more to find a solution using Java Scripting to use tokens as my description. I will instead use a gateway and then when the user click on “complete” button, then it should come back to the same task until the sub process has been completed.

 

This is being figured out in our UAT sandbox environment.

0 0
replied on April 7, 2021

Ok, I was focusing on getting the value from another form in the process. Which just requires sharing the same field. It will work with or without save as draft and even if they update the value in the draft, it will work since javascript is not looking directly at the backend variable.

0 0
replied on April 7, 2021 Show version history

The Save Draft button isn't supposed to update variables, so maybe Save Draft isn't actually what you want.

Maybe you could do something like

That'll update all the forms variables so other users can see the changes but the user on User Task can continue editing the form.

0 0
replied on April 7, 2021

The save draft will not update the variable in the backend for workflow to use, but since script reads directly from the field, by class name, his script would still register a change from a saved draft, if that is what he wants.

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

Sign in to reply to this post.