Create dynamic incident fields using an automation script. Create conditional fields.
Dynamic fields can display different data depending on the field value. You can control which fields display in an incident layout, new/edit, and close forms, and which values display for single-select and multi-select fields. You create a script on the Scripts page and then add the script to a field. Scripts support JavaScript, Python, and PowerShell.
Dynamic fields are useful in the following scenarios:
You want specific values to appear in a field when the value of another field is different. For example, if the value in the Owner field is
Admin
, the values in the assignee field should beJane
,Joe
, orBob
. If the value in the Owner field is anything else, the values in the assignee field should beMark
,Jack
, orChristine
.You can use display scripts to change the value displayed in single-select or multi-select fields in the layout. The field displays a list of options, but when selected, the field may show a different value in the layout than the one selected. For example, in a single-select field, select an incident from a list of incident names, but the field is populated with the incident ID (not the name) of the related incident.
When assigning an incident to a user, you want to see only relevant data according to the user’s role.
Create a script.
Go to the Scripts page and select New Script.
Give the script a descriptive name.
Enter a useful description.
Under Tags, select
field-display
.This tag must be applied for the script to be available in the field you want to add the script.
Write the script.
Cortex XSOAR comes out-of-the-box with the
hideFieldsOnNewIncident
field-display script, which hides the incident field for new incidents, but appears when editing an incident.The field script contains the following.
Name
Description
demisto.incidents
The incident in which this script is running.
field
The field attributes. Add metadata to the field, such as
cliName
,type
,select values
, etc. For example,[‘field’] [‘cliName’]
is the machine learning name of the field.formType
Enables Cortex XSOAR to process the script in the
new
,edit
,close
incident forms. For example, you may want the field to appear in the close form and not in the edit form.incident.get (‘
field’)
The field within the incident. For example,
incident.get.(‘owner’)
retrieves theowner
field. If you create a custom field, you need to change this toCustomFields
. For example, for theincidentclassification
custom field, type:if incident.get('CustomFields').get('incidentclassification')
.demisto.results
The results to return.
currentUser
Specifies the current user. For example, if you want the script to check on a role assigned to user and display the appropriate output, type the following:
demisto.executeCommand("getUserByUsername", {"username": demisto.args()["currentUser"] })
Add the information that you want to display according to the user roles.
Create an incident field.
Select
→ → → → → .If you want to add the script to an existing field, select the field and click Edit.
Under Field Type, select the field type. For example, Single select.
Under Field Name, enter a descriptive name.
Under the Attributes tab, in the Field display script field, select the script you created in step 1.
Complete the remaining field definitions Save the field.