11. Patterns: Key/Value Tracking
In the previous section, we used Key/Values to create a correlation of a record between source and target apps. Another use for Key/Values is to report on success or failure information. Generally, a Key/Value group will be used for reporting purposes while another Key/Value group is used to correlate between source and target apps.
We'll create a simpler version of the previous Workflow to illustrate how Key/Values should be used to store sync status and then report on it.
Exercise 14. Key/Value Creation
In this exercise we'll create a simple Workflow that attempts to integrate contacts to a web service and then records the outcome in a Key/Value group.
Add
Flat File, connectStart.RunNow → Flat File.Set
Flat File.FlatFileDocumentto the value below:Id,First Name,Last Name,Email,Phone,Company Name,State 1,Dennis,Brown,juanjennings@hotmail.com,001-670-283-7481,Pioneer Pharmaceuticals,West Virginia 2,Joseph,Lucas,sean27@gmail.com,422.631.1017x95303,Ascend Healthcare Partners,New York 3,Robert,Medina,william51@gmail.com,8737236607,Apex Innovations,South Dakota 4,Matthew,Flowers,valenzuelarodney@howell-walters.com,758.052.9923,EchoNet Communications,New York 5,Jacqueline,Carroll,edwardhodge@yahoo.com,203-862-8915x3140,Vertex Construction,Alaska 6,Diana,Harrison,andrea83@yahoo.com,547.430.8570,GreenLeaf Agriculture,Arkansas 7,Mary,Jackson,robertsmith@caldwell.info,001-247-971-0674x837,Insight Marketing Solutions,Indiana 8,Kelly,Richardson,sandra16@johnson.net,001-309-461-5944x9969,Swift Logistics,Pennsylvania 9,Jay,Taylor,larry55@yahoo.com,001-036-973-5467,Skyline Engineering,New York 10,Tina,Hill,savannahrussell@glover.com,0018245617,BlueHorizon Travel,IdahoSet
Flat File.ColumnDelimiterto,andFlat File.HasColumnNamestoTrue.'Add
JSON Convert, connectFlat File → JSON Convert.Set
JSON Convert.ActiontoXmlToJson.Connect
Flat File.XmlDocumenttoJSON Convert.Xml.Run the Workflow to confirm the content is being parsed correctly and to make sample data available.
Add
For Each, connectJSON Convert → For Each.Connect
JSON Convert.Json → For Each.SourceDocument.Set
For Each.PathtoDocument.Row[*](click theRowelement in the tree view that is shown when you focus the Property).Run the Workflow to propagate sample data through the
For EachNode.Add
Web Request 2and connectFor Each.Item → Web Request 2.Set
Web Request 2.MethodtoPOSTandUrltohttps://zorkco.flowgear.net/contacts?auth-key={auth}Add
Web Request 2.auth, set it todMFROUiQadVEWaHZe8qTEHM9TieeyGo7PBhY9Ln1TwKCsGu-sfgnJUh4OKIrBZLplNtXKWdcJDdqgHjVScr24Q.Set
Web Request 2.RequestHeaderstoContent-Type: application/json.Connect
For Each.Item → RequestBody.Add
Set Key-Value 2, rename toTag Success, connectWeb Request 2 → Tag Success.Set
Tag Success.Grouptocontact-syncand setTag Success.StatustoSuccess.Connect
For Each.Item → Tag Success.Keyand set the Data Mapping Expression toId.Add a second
Set Key-Value 2belowTag Successand rename it toTag Error, connectWeb Request 2.Error (Execution Output) → Tag Error.Set
Tag Error.Grouptocontact-syncand setTag Error.StatustoError.Connect
For Each.Item → Tag Error.Keyand set the Data Mapping Expression toId.Connect
Start.Last_Error_Info → Tag Error.Value.In the ETL Exercise, we configured a Connection on the
Web Request 2Node to return error information in theResponseBodyProperty. For this exercise, we're keeping things a little simpler.When the contact record can't be integrated into the web service, the
Web Request 2Node will generate an error and the text of that error is available in theStart.Last_Error_InfoProperty.At this point you should be able to run the Workflow successfully and all contact records should be sync'd to the web service.
Next, remove the
Emailvalue on a few of the contacts and run the Workflow again. For those contacts, the web service call should fail and you should see theTag ErrorNode being invoked.
Save and run your Workflow, then click Submit Exercise to grade it.
Exercise 15. Key/Value Reporting
We will now generate a report of the Key/Values that we recorded in the previous exercise.
Add
Get Key-Values 2to a new Workflow and connectStart.RunNow → Get Key-Values 2.Set
Get Key-Values 2.MatchGrouptocontact-sync.Set
Get Key-Values 2.EmittoXmlAdd
Exceland connectGet Key-Values 2 → Excel.Set
Excel.ActiontoCreate.Connect
Get Key-Values 2.Result → Excel.TableXml.Add
Email Alert, connectExcel → Email Alert.Set
Email Alert.Recipientsto your email address.Set
Email Alert.SubjecttoYour Report.Set
Email Alert.AttachmentNametoReport.xlsx.Connect
Excel.ExcelDocument → Email Alert.Attachment.Add
Variable Bar.Add
Variable Bar.Report, set it to typeFileand set the file extension toxlsx.Connect
Excel.ExcelDocument → Variable Bar.Report.Run the Workflow and check that you can download the report from the
ReportProperty of theStartWorkflow Log and that you have received the email containing the report in an attachment.To keep this exercise simple, we've generated the Excel sheet from the raw Key/Value data. In a real-world scenario, you could use QuickMap to provide additional useful information to the user.
Save and run your Workflow, then click Submit Exercise to grade it.