Home

Results 1 to 3 of 3

Thread: Share data among activities

Hybrid View

  1. #1
    hello amigo NNTP User

    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.NativeArr ay@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


  2. #2
    Join Date
    Apr 2008
    Posts
    176

    Re: Share data among activities

    https://developer.mozilla.org/en-US/...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.NativeArr ay@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?*
    >
    >



  3. #3
    hello amigo NNTP User

    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.NativeArr ay@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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •