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.FlatFileDocument
to 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,Idaho
Set
Flat File.ColumnDelimiter
to,
andFlat File.HasColumnNames
toTrue
.'Add
JSON Convert
, connectFlat File → JSON Convert
.Set
JSON Convert.Action
toXmlToJson
.Connect
Flat File.XmlDocument
toJSON 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.Path
toDocument.Row[*]
(click theRow
element in the tree view that is shown when you focus the Property).Run the Workflow to propagate sample data through the
For Each
Node.Add
Web Request 2
and connectFor Each.Item → Web Request 2
.Set
Web Request 2.Method
toPOST
andUrl
tohttps://zorkco.flowgear.net/contacts?auth-key={auth}
Add
Web Request 2.auth
, set it todMFROUiQadVEWaHZe8qTEHM9TieeyGo7PBhY9Ln1TwKCsGu-sfgnJUh4OKIrBZLplNtXKWdcJDdqgHjVScr24Q
.Set
Web Request 2.RequestHeaders
toContent-Type: application/json
.Connect
For Each.Item → RequestBody
.Add
Set Key-Value 2
, rename toTag Success
, connectWeb Request 2 → Tag Success
.Set
Tag Success.Group
tocontact-sync
and setTag Success.Status
toSuccess
.Connect
For Each.Item → Tag Success.Key
and set the Data Mapping Expression toId
.Add a second
Set Key-Value 2
belowTag Success
and rename it toTag Error
, connectWeb Request 2.Error (Execution Output) → Tag Error
.Set
Tag Error.Group
tocontact-sync
and setTag Error.Status
toError
.Connect
For Each.Item → Tag Error.Key
and 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 2
Node to return error information in theResponseBody
Property. 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 2
Node will generate an error and the text of that error is available in theStart.Last_Error_Info
Property.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
Email
value 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 Error
Node 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 2
to a new Workflow and connectStart.RunNow → Get Key-Values 2
.Set
Get Key-Values 2.MatchGroup
tocontact-sync
.Set
Get Key-Values 2.Emit
toXml
Add
Excel
and connectGet Key-Values 2 → Excel
.Set
Excel.Action
toCreate
.Connect
Get Key-Values 2.Result → Excel.TableXml
.Add
Email Alert
, connectExcel → Email Alert
.Set
Email Alert.Recipients
to your email address.Set
Email Alert.Subject
toYour Report
.Set
Email Alert.AttachmentName
toReport.xlsx
.Connect
Excel.ExcelDocument → Email Alert.Attachment
.Add
Variable Bar
.Add
Variable Bar.Report
, set it to typeFile
and set the file extension toxlsx
.Connect
Excel.ExcelDocument → Variable Bar.Report
.Run the Workflow and check that you can download the report from the
Report
Property of theStart
Workflow 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.