task.dumpEntry( work ); system.skipEntry();
When placed at the appropriate point in the flow of an AssemblyLine, this SC then displays the contents of the work object by writing it to log output and then skip the rest of the AssemblyLine for this cycle. By moving the SC up and down the component list, you control how much of the AssemblyLine is actually executed. If you swap out the system.skipEntry() call with system.skipTo("ALComponentName"), you directly pass control to a specific AssemblyLine Component.
We can also use SCs to drive other components. A typical scenario when doing directory or database synchronization is having to handle both updated and deleted information. Since Connectors powered by the built-in AssemblyLine workflow can only operate in one mode at a time (Update or Delete) we will need to extend this logic a bit with our own code. One method is to add two Connectors, one in Update mode and one in Delete mode, and then put code in the Before Execute Hook in each Connector's to tell it to skip change operations that it should not handle. For example, in the Before Execute Hook of the Update Connector you would write something like this:
// The LDAP change log contains an attribute called "changeType" if (work.getString("changeType").equals("delete")) system.ignoreEntry();This will cause your Update mode Connector to skip deleted Entries. You would have complementary code in the Before Execute Hook of the Delete mode Connector, skipping everything but deletes.
However, if you are synchronizing updates to multiple targets, this would require you to have two Connectors per data source. Another approach is to have a single Connector in Passive state that you power from script. As an example, let's say we have a Passive AssemblyLine Connector called synchIDS. We can then add an SC with the following code to run it:1
if (work.getString("changeType").equals("delete")) synchIDS.deleteEntry( work ) else synchIDS.update( work );As long as you label your SC clearly, indicating that it is running Passive Connectors, this approach will result in shorter AssemblyLines that will be easier to read and maintain. This is an example of having to choose between two best practices: keeping the AssemblyLine short, and using built-in logic versus custom script. However, in this case the goals of legibility and simplicity are best served by writing a little script.
The Script Component also comes in handy when we want to test logic and script code. Just create an AssemblyLine with a single Script Component in the data Flow list, put in your code and run it.
Parent topic: The AssemblyLine
Passive Connectors are not run by the AssemblyLine logic, it does not matter
where they appear in the Data Flow list.