- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
03-04-2024 01:13 PM
Hello !!
I have created an automation to execute a SQL query (SELECT), however additional fields appear in the result ("module name", "brand", etc). How can I remove these fields? My intention is to email the result of the SELECT query only the fields that are within the query. Thank you
03-05-2024 05:32 AM
Hello
You have several ways to do that :
1) In your automation when you call another automation use execute_command() instead of demisto.executeCommand(). But like that you can use some automations like is_error().
2) With demisto.executeCommand() the data you want are present under the [0]["Contents"]. The index 0 can change if your executed command have multiple outputs.
# Code
results = demisto.executeCommand("SQLQuery")
if is_error(results):
demisto.error(results[0].get('Contents'))
return
demisto.results(results[0].get('Contents'))
03-05-2024 08:12 AM
Thanks for your response, I have tried the following without success:
a= demisto.executeCommand("sql-command", {"query":"select record_number, date_time, esg_message_id from [esglogdb76_40].[dbo].[esg_detail_policy_process_results_email_address]"})
if is_error(a):
demisto.error(a[0].get('Contents.record_number'))
return demisto.results(a[0].get('Contents.record_number')
"record_number" is a field in the sql query This gives me an error:
Command: !SQL-SCRIP Hide
reason reason
Error from Scripts is: Script failed to run:
Error: [Traceback (most recent call last):
File "<string>", line 8
demisto.results(a[0].get('Contents.record_number')
^
SyntaxError: '(' was never closed
] (2604) (2603)
03-06-2024 03:26 AM - edited 03-06-2024 03:36 AM
You just forgot a ')' in your code at line 8.
Write "demisto.results(a[0].get('Contents'))" instead of "demisto.results(a[0].get('Contents.record_number')"
By checking your post in this topic https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/xsoar-playbook-sql-query/td-p/578755 , 'Contents' will be typed as list and not dict, so you can't use .get() method on a list.
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!