- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
07-19-2023 07:25 AM
Hi all,
I have two custom fields. Initially, these fields were added to the context data even if they are empty. Now, they don't get added at all. This code used to work demisto.incident()['customFields']['fieldhere']
to grab the custom fields, but now it returns a KeyError
error.
Any advice?
07-19-2023 12:10 PM
fixed with date_ack = demisto.incident()['CustomFields'].get('dateacknowledged')
07-19-2023 07:45 AM
It should be demisto.incident()['CustomFields']['fieldname']
You can always print each get to make sure your getting what you think you're getting. I.e print(demisto.incident()['CustomFields'])
In regards to the fields, were the custom fields added after the Incident was created? If so they won't be in the incident object as they didn't exist at the time of creation, you'll need to use the setIncident builtin command to add a value to make them appear.
If it's a new Incident, make sure the fields are associated with the Incident Type or all Types before creation.
07-19-2023 08:04 AM
Ah, that's right! I did have 'CustomFields', but it still returns a KeyError. The fields are added to all incident types. Initially, I didn't need to set these fields. I could just access them via that code. But now it's not working. They are not showing in new incidents.
07-19-2023 08:10 AM
Is the field perhaps restricted to specific Incident Types? And the Incident you are testing on isn't one of those?
07-19-2023 08:37 AM
I don't think so. The 'Add to all incident types' is checked.
What I'm trying to do is check if the field is empty or not. If it's empty, add a value. But I'm unable to do this because when I check for the field, I get a KeyError error. (FYI: I'm trying to do these things via automation)
07-19-2023 12:10 PM
fixed with date_ack = demisto.incident()['CustomFields'].get('dateacknowledged')
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!