Hi Gabriel,
The "Create CSV Table" function allows you to convert a CSV file (from an attachment or sent directly to the function) into a row in a datatable. It uses a string-encoded JSON mapping to know what CSV fields to assign to the datatable columns. If your CSV file has a header line, your mapping input would look similar to this:
'{ "header1": "columnA", "headerX": "columnY" }'.
If the CSV file does not have a header line, your mapping input would refer to the position of the CSV file field to the datatable column similar to '{0: "columnA", 1: "columnY"}'. Hopefully the documentation and example workflow can guide you through the function setup.
As you stated, the "Get All Data Table Rows" function would be used to collect the datatable data which you would feed to your outbound email function. I believe you'll need some scripting logic to parse the results into the format needed for outbound email. Here's a snippet of my output from "Get All Data Table Rows" and my script to parse it. I put this together quickly so review for your needs
{
'version': 2.0,
'success': True,
'reason': None,
'content': {
'rows': [
{
'id': 1,
'cells': {
'attachments': {
'id': 'attachments',
'row_id': 1
},
'body': {
'id': 'body',
'row_id': 1,
'value': '<div class="rte"><div>message</div><div>here</div></div>'
},
'date_sent': {
'id': 'date_sent',
'row_id': 1,
'value': 1676264400000
},
'from': {
'id': 'from',
'row_id': 1,
'value': 'a@example.com'
}
}
]
}
}
The logic to convert this into HTML for outbound email would be similar to this:
results = playbook.functions.outputs.<your function output name>
header = ["<tr><th>{}</th></tr>".format(k) for k,v in results['content']['rows'][0]['cells'].items() ]
rows = []
for r in results['content']['rows']:
cols = ["<td>{}</td>".format(v.get('value')) for k,v in r['cells'].items() ]
rows.append("<tr>{}</tr>".format("".join(cols)))
table = ['<table>']+header+rows+['</table>']
table_formatted = '\n'.join(table)
------------------------------
Mark Scherfling
------------------------------
Original Message:
Sent: Fri February 10, 2023 09:02 AM
From: Gabriel Covello
Subject: Fill datatable with a CSV file
Hi everyone!
I'm new in IBM SOAR, and I'm trying to create the following playbook:
- The playbook activates when a file has been attached to the incident
- This file (a .csv) must fill a datatable
- This datatable must be sent by email
I'm currently using the "Create CSV Table" and the "Get All Data Table Rows" functions, but I'm not quite sure how to use them.
Thank you!
------------------------------
Gabriel Covello
------------------------------