Tip: Generate XML with Velocity template with array/list data
Spent some time with null checks in the velocity template and would like to share the findings: If you have data in an array such as this example: [ { "Lines": [ { "TEST1": null, "TEST2": "Text" } ] } ] If you try to do a null and empty value check using standard velocity methods (such as this) you will run in to problems when the input data is from an array. Normally when doing null and empty checks you can simply use #if($TEST1 && $TEST1 != "") dosomething #end But when processing data in the array this will not work (the evaluation will be true even if the JSON input value is null: #if($Lines[0].TEST1 && $TEST1 != "") dosomething #end This will work (null value, empty value or if the variable does not exist in the array): #if($Lines[0].TEST1 != "***NO DATA***" && $Lines[0].TEST1 != "") dosomething #end Same think if you are in a #foreach loop #foreach($Line in $Lines) #if($Line.TEST1 != "***NO DATA***" && $Line.TEST1 != "") dosomething #end #end The thing where the value is set to ***NO DATA*** seem to be a SnapLogic behaviour, maybe someone can confirm this? I hope this will save someone a few hours.4.3KViews3likes1CommentAn XML Generator & XML Formatter Snaps example
Here’s an example illustrating the use case of the snaps XML Generator, XML formatter and File writer. The 1st snap “XML Generator” of the pipeline generates a document format data with the given xml input configured in the snap on “Edit XML *” in snap settings. The 2nd snap “XML Formatter” accepts the document format and encapsulates the data into XML formates and provides the the binary output which can be an input to the File writer snap which accepts the binary input. Attached is the .slp for pipeline reference.XMLGenerator_Formatter_2017_03_1.slp (4.1 KB)4.6KViews1like1Comment