Anonymous_User Absent Member.
Absent Member.
222 views

Share data among activities


Hi! The standard way to share data among Activities in WF is the Mapping
Activity. We can save data into the "flowdata" object using "Target
Expression" and "Source Expression" columns. Then in order to access a
variable it is needed to call the flowdata.get('var_path') function.
There are some limitations I experienced using this way:
1. If we create two variables in the same Mapping Activities then it is
not possible to reference each other in the scope of its Mapping
Activity. It is possible to get the variable at least at the -next-
Activity.
2. It isn't easy to pass/get an array of data among variables. In order
to get array one should use "xml node" functions to get an array of data
(as I remember).

But there is another way to share data in the WF. It is using just
variables.
1. If two "flowdata" variables are declared in the same Mapping Activity
then we can share JS variables among this "flowdata" variables.
For example, there are two "flowdata" variables in the same Mapping
activity:
1)flowdata.VAR/a

Source Expression:

Code:
--------------------
var b = [10, 11];

(function () {
return "A";
})()
--------------------


2) flowdata.VAR/b
Source Expression:

Code:
--------------------
b
--------------------

Here we share variable "b" among "flowdata" variables in the scope of
the same Mapping Activity.

Then if we add as a next Activity a "log" Activity, for instance, we can
access "flowdata" variables as well as JS variables:

Code:
--------------------
java.lang.System.out.println("### flowdata.get(VAR/a): " + flowdata.get('VAR/a'));
java.lang.System.out.println("### flowdata.get(VAR/b): " + flowdata.get('VAR/b'));

java.lang.System.out.println("### b: " + b);
java.lang.System.out.println("### toString(b): " + Object.prototype.toString.call(b));
java.lang.System.out.println("### b[0]: " + b[0]);
java.lang.System.out.println("### b.join(,): " + b.join(","));
--------------------

=======
Output is:

Code:
--------------------
2015-03-04 10:03:37,731 INFO [STDOUT] (pool-26-thread-9) ### flowdata.get(VAR/a): A
2015-03-04 10:03:37,731 INFO [STDOUT] (pool-26-thread-9) ### flowdata.get(VAR/b): com.novell.soa.script.mozilla.javascript.NativeArray@140504e
2015-03-04 10:03:37,732 INFO [STDOUT] (pool-26-thread-9) ### b: 10,11
2015-03-04 10:03:37,732 INFO [STDOUT] (pool-26-thread-9) ### toString(b): [object Array]
2015-03-04 10:03:37,733 INFO [STDOUT] (pool-26-thread-9) ### b[0]: 10
2015-03-04 10:03:37,733 INFO [STDOUT] (pool-26-thread-9) ### b.join(,): 10,11

--------------------

*My question is Can I rely on the second approach? Is it work as
designed?*


--
hello_amigo
------------------------------------------------------------------------
hello_amigo's Profile: https://forums.netiq.com/member.php?userid=211
View this thread: https://forums.netiq.com/showthread.php?t=52980

Labels (1)
0 Likes
2 Replies
jtl1 Absent Member.
Absent Member.

Re: Share data among activities

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var
"The scope of a variable declared with var is its current execution context, which is either the enclosing function or, for
variables declared outside any function, global."

Regardless of this I would never use this method. How can you be sure that the JavaScript interpreter isn't killed and reloaded
between two activities? Obviously it works for you in this test but imagine a scenario where you have an approval activity and
while the WF is waiting for the approval the application server is restarted?

Best regards,
Tobias

On 2015-03-04 09:24, hello amigo wrote:
>
> Hi! The standard way to share data among Activities in WF is the Mapping
> Activity. We can save data into the "flowdata" object using "Target
> Expression" and "Source Expression" columns. Then in order to access a
> variable it is needed to call the flowdata.get('var_path') function.
> There are some limitations I experienced using this way:
> 1. If we create two variables in the same Mapping Activities then it is
> not possible to reference each other in the scope of its Mapping
> Activity. It is possible to get the variable at least at the -next-
> Activity.
> 2. It isn't easy to pass/get an array of data among variables. In order
> to get array one should use "xml node" functions to get an array of data
> (as I remember).
>
> But there is another way to share data in the WF. It is using just
> variables.
> 1. If two "flowdata" variables are declared in the same Mapping Activity
> then we can share JS variables among this "flowdata" variables.
> For example, there are two "flowdata" variables in the same Mapping
> activity:
> 1)flowdata.VAR/a
>
> Source Expression:
>
> Code:
> --------------------
> var b = [10, 11];
>
> (function () {
> return "A";
> })()
> --------------------
>
>
> 2) flowdata.VAR/b
> Source Expression:
>
> Code:
> --------------------
> b
> --------------------
>
> Here we share variable "b" among "flowdata" variables in the scope of
> the same Mapping Activity.
>
> Then if we add as a next Activity a "log" Activity, for instance, we can
> access "flowdata" variables as well as JS variables:
>
> Code:
> --------------------
> java.lang.System.out.println("### flowdata.get(VAR/a): " + flowdata.get('VAR/a'));
> java.lang.System.out.println("### flowdata.get(VAR/b): " + flowdata.get('VAR/b'));
>
> java.lang.System.out.println("### b: " + b);
> java.lang.System.out.println("### toString(b): " + Object.prototype.toString.call(b));
> java.lang.System.out.println("### b[0]: " + b[0]);
> java.lang.System.out.println("### b.join(,): " + b.join(","));
> --------------------
>
> =======
> Output is:
>
> Code:
> --------------------
> 2015-03-04 10:03:37,731 INFO [STDOUT] (pool-26-thread-9) ### flowdata.get(VAR/a): A
> 2015-03-04 10:03:37,731 INFO [STDOUT] (pool-26-thread-9) ### flowdata.get(VAR/b): com.novell.soa.script.mozilla.javascript.NativeArray@140504e
> 2015-03-04 10:03:37,732 INFO [STDOUT] (pool-26-thread-9) ### b: 10,11
> 2015-03-04 10:03:37,732 INFO [STDOUT] (pool-26-thread-9) ### toString(b): [object Array]
> 2015-03-04 10:03:37,733 INFO [STDOUT] (pool-26-thread-9) ### b[0]: 10
> 2015-03-04 10:03:37,733 INFO [STDOUT] (pool-26-thread-9) ### b.join(,): 10,11
>
> --------------------
>
> *My question is Can I rely on the second approach? Is it work as
> designed?*
>
>


0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: Share data among activities


Tobias Ljunggren;254806 Wrote:
> http://tinyurl.com/o59tw98
> "The scope of a variable declared with var is its current execution
> context, which is either the enclosing function or, for
> variables declared outside any function, global."
>
> Regardless of this I would never use this method. How can you be sure
> that the JavaScript interpreter isn't killed and reloaded
> between two activities? Obviously it works for you in this test but
> imagine a scenario where you have an approval activity and
> while the WF is waiting for the approval the application server is
> restarted?
>
> Best regards,
> Tobias
>
> On 2015-03-04 09:24, hello amigo wrote:
> >
> > Hi! The standard way to share data among Activities in WF is the

> Mapping
> > Activity. We can save data into the "flowdata" object using "Target
> > Expression" and "Source Expression" columns. Then in order to access a
> > variable it is needed to call the flowdata.get('var_path') function.
> > There are some limitations I experienced using this way:
> > 1. If we create two variables in the same Mapping Activities then it

> is
> > not possible to reference each other in the scope of its Mapping
> > Activity. It is possible to get the variable at least at the -next-
> > Activity.
> > 2. It isn't easy to pass/get an array of data among variables. In

> order
> > to get array one should use "xml node" functions to get an array of

> data
> > (as I remember).
> >
> > But there is another way to share data in the WF. It is using just
> > variables.
> > 1. If two "flowdata" variables are declared in the same Mapping

> Activity
> > then we can share JS variables among this "flowdata" variables.
> > For example, there are two "flowdata" variables in the same Mapping
> > activity:
> > 1)flowdata.VAR/a
> >
> > Source Expression:
> >
> > Code:
> > --------------------
> > var b = [10, 11];
> >
> > (function () {
> > return "A";
> > })()
> > --------------------
> >
> >
> > 2) flowdata.VAR/b
> > Source Expression:
> >
> > Code:
> > --------------------
> > b
> > --------------------
> >
> > Here we share variable "b" among "flowdata" variables in the scope of
> > the same Mapping Activity.
> >
> > Then if we add as a next Activity a "log" Activity, for instance, we

> can
> > access "flowdata" variables as well as JS variables:
> >
> > Code:
> > --------------------
> > java.lang.System.out.println("### flowdata.get(VAR/a): " +

> flowdata.get('VAR/a'));
> > java.lang.System.out.println("### flowdata.get(VAR/b): " +

> flowdata.get('VAR/b'));
> >
> > java.lang.System.out.println("### b: " + b);
> > java.lang.System.out.println("### toString(b): " +

> Object.prototype.toString.call(b));
> > java.lang.System.out.println("### b[0]: " + b[0]);
> > java.lang.System.out.println("### b.join(,): " + b.join(","));
> > --------------------
> >
> > =======
> > Output is:
> >
> > Code:
> > --------------------
> > 2015-03-04 10:03:37,731 INFO [STDOUT] (pool-26-thread-9) ###

> flowdata.get(VAR/a): A
> > 2015-03-04 10:03:37,731 INFO [STDOUT] (pool-26-thread-9) ###

> flowdata.get(VAR/b):
> com.novell.soa.script.mozilla.javascript.NativeArray@140504e
> > 2015-03-04 10:03:37,732 INFO [STDOUT] (pool-26-thread-9) ### b:

> 10,11
> > 2015-03-04 10:03:37,732 INFO [STDOUT] (pool-26-thread-9) ###

> toString(b): [object Array]
> > 2015-03-04 10:03:37,733 INFO [STDOUT] (pool-26-thread-9) ### b[0]:

> 10
> > 2015-03-04 10:03:37,733 INFO [STDOUT] (pool-26-thread-9) ###

> b.join(,): 10,11
> >
> > --------------------
> >
> > *My question is Can I rely on the second approach? Is it work as
> > designed?*
> >
> >


Very good point. Thank you.
So using this method to pass data among Activities is a dangerous way.


--
hello_amigo
------------------------------------------------------------------------
hello_amigo's Profile: https://forums.netiq.com/member.php?userid=211
View this thread: https://forums.netiq.com/showthread.php?t=52980

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.