
Problem
You would like to know the labels of all outgoing connections from a Screen in a Screenflow. Why? Maybe you would like to put this into a template in order to dynamically display a button for every outgoing connection?

Solution

The next step is to get the required information out of this Screenflow Token. We are interested in the id of the Screenflow and in the element id of the current Screen Task in the Screenflow.
Given the Screenflow id, we may load the Screenflow model (Business Object).
The function "GETBUSINESSOBJECT" has an optional 3 parameter: a Version Filter. If you don't specify a value for this parameter, the function uses the current Version Filter, which is appropriate as long as you use this code somewhere inside the current Screenflow Instance.
Now you can search for the Screen Task with the given element id.
Note that the method "getElementById" used in the above statement is a method of the Java class "Screenflow". You therefore have to cast the reference to the Screenflow Business Object to the correct type, or the editor doesn't show you this method in the code completion pop-up.
The method "getElememtById" returns a reference to an instance of Java class "Element". This is the base class for all Screenflow elements, including "ScreenTask", "Connection" or "Gateway". But not all of them have outgoing connections. Elements which may have outgoing (and incoming) connections are called "nodes". The Java class "Node" is used as super class for all these elements.
In order to get the outgoing connections, you first have to cast your Element reference to a Node reference. Then you may call the method "getOutgoingConnections()" to get a list with the outgoing connections. The return value of this method is a Java list, not an indexed collection. But you can use the function "ToIndexed" to convert it to an indexed collection.
Now you may iterate over the indexed collection and extract the label texts.
You can also use the methods "getType()" and "getExpression()" to retrieve the connection type ("None", "Default" or "Expression") and connection condition (if type is set to "Expression").
Script Function
You can put all this code into a single Script Function. The code below shows an example implementation. There are some additional checks, but basically it is the logic described above.
You can download this Script Function as export package from the following URL:
http://support.numcom.com/htdocs/downloads/public/howtos/GetOutgoingConnectionLabels.awexport

Comments (0)