Let's start by configuring Null Behavior. Do this by right-clicking on the 'Read_CSV_File' Connector in the Attribute Maps panel (not in the AssemblyLine components tree-view) and selecting Null Behavior from the context menu1.
Null Behavior button for AL-level configuration
This brings up the Null Behavior dialog where we can configure both how null is defined - which can vary depending on the type of source you are reading from - as well as how this situation should be handled. By default, null means that an Attribute is missing, and the default handling is to remove this Attribute from the mapping operation. The end result of this is that no Attribute with the specified name will be found in the receiving Entry.
Once in the Null Behavior dialog, use the radio buttons on the right to define null as an empty string value, and then those on the left to specify a default value of "* missing *" to be returned in this case.
Null Behavior configuration dialog
Re-run your AssemblyLine and refresh the browser window displaying the contents of Output.xml. The entry for 'Roger' should now have the special null value ("* missing *") for 'Title' and 'LastName'.
Result in the XML output of Null Behavior settings
This is somewhat better - at least it's a conscious choice. However, sometimes an entry is just too incomplete to continue processing. In our scenario we need at least values for 'FirstName' and 'LastName' in order to compute 'FullName', so we will now add filtering logic to our AssemblyLine to ensure that all entries fulfill this requirement.
Start by clicking the Insert Component button again and then choosing Control/Flow Components from the radio buttons at the left. Then select 'IF' in the list, name it 'Incomplete data'2 and press Finish.
Selecting the IF branch component
Now drag this IF branch above the output Connector. The IF branch editor area lets you add your conditions.
Editing conditions for the IF branch
Here we have the option of adding simple conditions or writing a snippet of Script - or both. Note the Match All checkbox that decides whether your Conditions (simple and scripted) are evaluated with an implied OR between them when this is unchecked, or with AND when it is selected.
Add a simple condition by pressing the Add button. Then pick the 'First' Attribute from the leftmost drop-down and then the 'has value(s)' operator. Negate this condition by toggling the not column value. Nothing needs to be specified in the right-most field when using the 'has value(s)' operator. Now add a similar has no values condition for the Attribute named 'Last' as well. Finally, make sure the Match All checkbox is unchecked – which implies Match Any - so that the lack of values for either Attribute will trigger this branch.
Adding simple Conditions to the IF branch
An IF Branch diverts the execution flow of the AssemblyLine whenever the specified Conditions evaluate to true. In your case, processing will continue to those components placed under the branch if either the 'First' or 'Last' Attributes do not have values assigned to them - or even if either does not exist in the Work Entry. In other words, the 'has value(s)' operator also includes the check for 'exists'.
task.logmsg("*** Skipping incomplete entry");
The task variable used here references the AssemblyLine itself, and it provides you with a number of useful functions like the logmsg() method. This scripted call causes the specified text message to be written to our log output.
To make log output even more informative, let's include the current contents of the Work Entry as well. Do this by right-clicking on the IF branch, selecting Add Component... and again choosing the radio button for Scripts. This time select the pre-defined Script component labeled 'Dump Work Entry'.
Finally, instruct the AssemblyLine to stop the current cycle at this point and return control to the Iterator Connector so that it can read in the next CSV line, effectively filtering the current Entry from the XML output. Unless you specify this behavior yourself then control will continue to the first component after the IF branch. So once again right-click on your IF branch and then on Add Component... Choose Scripts and then select the SC called 'Exit Flow'. Now your AssemblyLine should look like this:
Your first complete AssemblyLine
Before running your AssemblyLine again we will need to open the Null Behavior dialog once more and restore both the default definition and behavior selections - otherwise your IF Branch conditions will never evaluate to true.
Resetting Null Behavior for the AssemblyLine
Now when we run your AssemblyLine again we will see your message followed by the Work Entry dump:
Log output with your messages and Work Entry dump
From the statistics we can see that your IF 'Data incomplete' branch was true once, resulting in only six nodes being added to our XML output. If you again refresh the Data Browser window then you will see that 'Roger' is indeed gone.
Parent topic: Introducing IBM TDI
1 Or we can select the Connector itself in the AssemblyLine component list; press the More... button at the top of the Input Map and choose 'Null Behavior' there.
2 You were previously encouraged to name Connectors as you would a script variable. This also applies to Function components. However, it is less important for Attribute Map components, Branches, Loops and Scripts, since these are seldom accessed directly from script. In this guide higher priority has been given to making the AssemblyLine easy to read.
3 The Script editor
provides a feature called code-completion that shows
which options we have. For example, type "tas" in the Script editor
and then press the Ctrl + Space key combination to open the code-completion
drop-down, which should provide a single option: task.
If you press Enter then this choice is selected and entered in your
script. Now type the period key (.) so your script becomes "task."
and wait just a moment; We will see a new code-completion drop-down
appear, this time with a list of all the methods and properties that
we can access in the task object.