Temporary updatable variables in pageflow

1
0
-1

Hi.

I'm running Bonita Studio 6.3.2 Performance

I've put some transient vars in my start pageflow (ie. not of a human task).

Transient var

I update them using a Groovy script called when a field gets updated (ie. contingency)

import org.slf4j.Logger
import org.slf4j.LoggerFactory
Logger logger = LoggerFactory.getLogger("org.bonitasoft")
// here I'm updating transient variables
the_double = field_input_number * 2
the_square = field_input_number * field_input_number

// then I log new values
logger.info("Double after update = ${the_double}") // in log I see that transient value is as expected
logger.info("Square after update = ${the_square}") // in log I see that transient value is as expected
return the_double

As form submit actions, I update two process variables: triple gets the output of a script that uses the_double value, and square gets the value of the_square transient var.

Form actions

import org.slf4j.Logger
import org.slf4j.LoggerFactory
Logger logger = LoggerFactory.getLogger("org.bonitasoft")
logger.info("Double when submitting form = ${the_double}")
return the_double + field_input_number

When the last script is executed in log I see the_double is null and an exception is thrown because null cannot be added. The other process var, square, is 0, i.e. square got the default value of the_square and not that updated by the script.

Is this the expected logic of transient variables? Do they live only inside scripts using them and then get reset when scripts terminates?

Thanks in advance, Michael

1 answer

1
0
-1

Hello,

you cannot update variable values from within a Groovy script. And thiis is valid for any type of variable. You will have to take the output of your script and save it to a variable through an operation or an action. Lines 5 and 6 from your first script will not update task transient variables. Furthermore, it is not recommended to update transient variables, as you can read here .

Hope this helps, Haris

Comments

Submitted by mick80 on Tue, 08/05/2014 - 18:29

Thanks Haris.

So there is no way to have a temporary updatable variable, isn't it?

Michael

Submitted by haris.subasic on Wed, 08/06/2014 - 11:01

For the use case you described above in your question, you can do iit like this: You create a contingency on Its_double field, that triggers a script with:

return field_input_number * 2;

and another contingency on Its_square field that triggers a script with:

return field_input_number * field_input_number;

Than for both of these fields, on the Data tab, you leave the default operation that saves field_its_double1 and field_its_square1 (or similar) respectively to variables the_double and the_square.

Submitted by mick80 on Thu, 08/07/2014 - 10:41

In fact I'd like to backup a Map in a temporary variable: I've found no straight way to get the whole selected entry <label, value> from a select widget. I can get only the value associated to a label and it's always of type string. I tried populating with <label, <label,value>> but I get the string representation of <label,value>, not the map object. I can do some string processing of course, but I've thought there was a simpler way.

Any other suggestions?

Thanks again, Michael

Notifications