When MapForce reads or writes data, it is often the case that either the source or destination file or database has empty or null fields. To handle such cases, MapForce provides various built-in functions, if-else conditions, and other mechanisms that let you replace missing or null data with something else, or perhaps throw an exception when missing fields are encountered.
Furthermore, you may want to set a default value for multiple items simultaneously (for example, all children of an XML element). Alternatively, you may want to create a simple function that substitutes an empty value with some text (for example, "n/a"), and then apply this function to multiple items. Under normal circumstances, in order to do this, you would need to copy-paste the same function multiple times on the mapping. However, this would also add clutter to the mapping and make it more difficult to understand. As a simpler alternative, you could use defaults and node functions, which are the subject of this chapter.
|Note:||Defaults and node functions are supported when the target language of the mapping is BUILT-IN. Running such mappings from generated C#, C++, Java program code, or with generated XSLT/XQuery transformations is not supported. On the server side, you can execute such mappings with MapForce Server Advanced Edition.|
The term "node function" means that the function applies at node level, be it an XML node or CSV, JSON, EDI, or database field. The node function may apply either to a single item or to multiple items at once. Likewise, the term "default" refers to a default value that you want to apply at node level, for either a single item or multiple items. Note that, at mapping runtime, a node function or default is called once for each item in a sequence.
Defaults and node functions are particularly useful when you want to apply the same processing logic to multiple descendant items in a structure, for example:
|•||Every time when an empty or null value is encountered, replace it with some other value, and do this recursively for all descendant items|
|•||Every time when a specific value is encountered (for example, "N/A"), replace it with some other value (or with an empty string), and do this recursively for all descendant items|
|•||Replace all database null values with empty string or custom text (or with 0, in case of numeric fields) when reading from a database table|
|•||Trim all trailing spaces for all values that are coming from some source database|
|•||Append a custom prefix or suffix to all values that are written to a target file or database|
|•||Produce a null value each time when a specific value is encountered|
|Note:||It is important to distinguish between "null" and "empty" values, since they are not the same. A null value means "nothing" (the absence of a value), whereas an empty value is typically an empty string (''). MapForce provides various ways to handle both, including (but not limited to) node functions and defaults.|
© 2019 Altova GmbH