> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/python-development-quick-start-guide/cortex-xsoar-python-development-quick-start-guide/development-tools-and-resources/cortex-xsoar-automation-scripts/field-change-trigger.md).

# Field Change Trigger

You can create a script that is triggered when a field value changes.

This example automation creates a field called **textfield** that has a type **Short text** . Deleting all the characters triggers the field to display the text "ping" and typing characters in the field causes the field to display "pong".

1. Use the basic automation template to create the following code.

   ```programlisting
   def main():
       try:
           fieldValue = demisto.args()['new']
           if fieldValue == "":
               fieldValue = "ping"
           else:
               fieldValue = "pong"
           demisto.executeCommand("setIncident", {
               'textfield': fieldValue
           })
       except Exception as ex:
           demisto.error(traceback.format_exc())
           return_error("Failed to setIncident: " +
               str(ex)
           )

   if __name__ in ("__main__", "__builtin__", "builtins"):
       main()
   ```
2. Use the **Settings** button to add the **`field-change-triggered`** tag.

   This makes the automation available as a field change triggered automation. When a field change trigger script is invoked, the new and old values are passed as the **`new`** and **`old`** arguments to the script.

   ![cortex-xsoar-automation-field-change-trigger.png](/files/7wret63slHDlmlkKBkus)
3. Create a new incident field **textfield** that has a field type **Short text**. In the **Attributes** tab, select the **Script to run when field value changes** and select the automation just created.

   ![cortex-xsoar-automation-trigger-script-to-run.png](/files/MbcLCweRCPTTyG3ncD8w)
4. In the incident layout created previously (see [Add a Table to the Incident Layout](/python-development-quick-start-guide/cortex-xsoar-python-development-quick-start-guide/development-tools-and-resources/cortex-xsoar-automation-scripts/add-a-table-to-the-incident-layout.md)), add another section and add the **textfield** field just created.

   ![cortex-xsoar-automation-add-textfield.png](/files/7bddATY53EE1NDlOn35P)
5. Go to an incident and edit **textfield**. If you deleting all characters, the “ping” value displays. If you enter text, the “pong” value displays.

   ![cortex-xsoar-automation-show-ping.png](/files/ZbIWhF8UTDrkzWJETyEI)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/python-development-quick-start-guide/cortex-xsoar-python-development-quick-start-guide/development-tools-and-resources/cortex-xsoar-automation-scripts/field-change-trigger.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
