> 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/cortex-xsoar-8-on-prem/8.13/configure-cortex-xsoar/incident-configuration/incident-customization/incident-layout-customization/examples-of-using-scripts-in-incident-layouts.md).

# Examples of using scripts in incident layouts

Use scripts in incident layouts in Cortex XSOAR 8.13 On-prem.

The following are examples of scripts that are supported in incident layouts:

<details>

<summary>Charts</summary>

A valid result for a chart widget is a list of groups. Each group points to a single entity. For example, in bar charts, each group is a bar. A group consists of the following:

* `Name`: A string.
* `Data`: An array of integers.
* `Color`: A string representing a color that will be used as a default color for that group. It can be the name of the color, a hexadecimal representation of the color, or an RGB color value (optional).
* `Groups`: A nested list of groups (optional).

Horizontal bar

In this example, create a script in Python that displays a horizontal bar of the indicators by severity.

After you have uploaded the script and created the widget, you can add the widget to an incident layout. The following widget displays:

![vertical-bar-graph.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-952312269c14ded9940293065bcc83d3d16aba70%2F72b088b5cf85f4a0ce44ebfc1fa4f84deaaf383c9498562987caa0468c601f22.png?alt=media)

Vertical bar

In this example, create a script in Python that displays a vertical bar of the indicators by severity.

After you have uploaded the script and created the widget, you can add the widget to an incident layout. The following widget displays:

![horizontal-bar-graph3.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-135f901e8aa613763de7c22a40d47d01787659db%2Fec624455e789d9dd773e233f5e60549890d06f58fd0054c73bcfab0da2832eae.png?alt=media)

Stacked bar

In this example, create a script in Python that displays a stacked bar showing the successes and failures on specific dates.

After you have uploaded the script and created the widget, you can add the widget to an incident layout. The following widget displays:

![horizontal-bar-graph2.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-7c8186b2c86b9e501737905a93a947b20ef1ffe5%2F9513e3a0dd184ccd98bf44f23954d26093dceb6ffca3ea3f90fa675a0528e7bd.png?alt=media)

Line chart

In this example, we create a JavaScript that displays how many GitHub issues were created each week for Content, Documentation, and Platform in a line chart.

After you have uploaded the script and created the widget, you can add the widget to an incident layout. The following widget displays:

![widget-line.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-81e4bb34b13c039ee1a9ff3361486442ade42b46%2Fd6911aed5c86a964079b82afbb6a2009f2db1e6f8a8dfbaa8e53b760ff9f533a.png?alt=media)

</details>

<details>

<summary>Pie</summary>

In this example, create a script in Python that queries and returns a pie chart.

```programlisting
data = {
    "Type": 17,
    "ContentsFormat": "pie",
    "Contents": {
      "stats": [
        {
          "data": [
            1
          ],
          "groups": None,
          "name": "high",
          "label": "incident.severity.high",
          "color": "rgb(255, 23, 68)"
        },
        {
          "data": [
            1
          ],
          "groups": None,
          "name": "medium",
          "label": "incident.severity.medium",
          "color": "rgb(255, 144, 0)"
        },
        {
          "data": [
            2
          ],
          "groups": None,
          "name": "low",
          "label": "incident.severity.low",
          "color": "rgb(0, 205, 51)"
        },
        {
          "data": [
            8
          ],
          "groups": None,
          "name": "unknown",
          "label": "incident.severity.unknown",
          "color": "rgb(197, 197, 197)"
        }
      ],
      "params": {
          "layout": "horizontal"
      }
    }
  }

  demisto.results(data)
```

After you have uploaded the script and created the widget, you can add the widget to an incident layout. The following widget displays indicator severity as a pie chart:

![pie-chart.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-0f0c03ff227889dfde6cce995d27a1ca7ec82551%2Fad47915216e4494ec0e1bd39d2508cf4f0275029d8982e6bc5927467b7244e0d.png?alt=media)

</details>

<details>

<summary>Duration</summary>

In this example, create a script in Python that queries and returns a time duration (specified in seconds), and displays the data as a countdown clock.

```programlisting
 data = {
    "Type": 17,
    "ContentsFormat": "duration",
    "Contents": {
      "stats": 60 * (30 + 10 * 60 + 3 * 60 * 24),
      "params": {
          "layout": "horizontal",
          "name": "Lala",
          "sign": "@",
          "colors": {
            "items": {
              "#00CD33": {
                "value": 10
              },
              "#FAC100": {
                "value": 20
              },
              "green": {
                "value": 40
              }
            }
          },
        "type": "above"
      }
    }
  }

  demisto.results(data)
```

After you have uploaded the script and created the widget, you can add the widget to an incident layout. The following widget displays the time duration:

![duration.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-9a909107cceec86430cdd53ded2d17574ac1eabb%2F2da1d0e2bc488346e20458f108e30fb3280991ceb0a0d6510af89f1cbd1c8b6f.png?alt=media)

</details>

<details>

<summary>Number</summary>

This example shows how to create a single item widget that displays a number.

```programlisting
 data = {
    "Type": 17,
    "ContentsFormat": "number",
    "Contents": {
      "stats": 53,
      "params": {
          "layout": "horizontal",
          "name": "Lala",
          "sign": "@",
          "colors": {
            "items": {
              "#00CD33": {
                "value": 10
              },
              "#FAC100": {
                "value": 20
              },
              "green": {
                "value": 40
              }
            }
          },
        "type": "above"
      }
    }
  }

  demisto.results(data)
```

After you have uploaded the script and created the widget, you can add the widget to an incident layout. The following widget displays:

![number.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-21303e765b10ce82e8852f3a028dc6b51a1b5d95%2Fca35b4500ed3e1c3f4903e739071f170ffeb535f61cd83e5fad6a96ed41e63a7.png?alt=media)

</details>

<details>

<summary>Number Trend</summary>

This example shows how to create a single-item widget that displays a number trend.

```programlisting
data = {
    "Type": 17,
    "ContentsFormat": "number",
    "Contents": {
      "stats": { "prevSum": 53, "currSum": 60 },
      "params": {
          "layout": "horizontal",
          "name": "Lala",
          "sign": "@",
          "colors": {
            "items": {
              "#00CD33": {
                "value": 10
              },
              "#FAC100": {
                "value": 20
              },
              "green": {
                "value": 40
              }
            }
          },
        "type": "above"
      }
    }
  }

  demisto.results(data)
```

After you have uploaded the script and created the widget, you can add the widget to an incident layout. The following widget displays:

![number-trend.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-ff71c096b7fd28da4418bba61d09dc1555b88b89%2Fefe370a0cdf7aa069054b82b11c8f202fad1e81280b6fca3f9b5ab259e850097.png?alt=media)

</details>

<details>

<summary>Add note information</summary>

This example shows how to add note information to an incident layout using a script through the API.

1. Install the Cortex REST API content pack and add a Core REST API instance.
2. Go to the **Scripts** page and add the following script:

   ```programlisting
   commonfields:
     id: ShowLastNoteUserAndDate
     version: -1
   name: ShowLastNoteUserAndDate
   script: |2

     function getLastNote(incidentID) {
         var body = {pageSize:1,categories:['notes']};
         var res = executeCommand('demisto-api-post', {uri:'/investigation/' + incidentID, body: body});
         if (isError(res[0])) {
             throw 'demisto-api-post failed for incidnet #'+incidentID+'\nbody is ' + JSON.stringify(body) + '\n' + JSON.stringify(res);
         }
         if (!res[0].Contents.response.entries) {
             return null;
         }
         var notes = res[0].Contents.response.entries;
         var lastNote = notes[notes.length-1];
         return lastNote;
     }

     lastNote = getLastNote(incidents[0].id);

     if (lastNote) {
         md = `#### Update by ${lastNote.user} on ${lastNote.modified.split('T')[0]}\n`;
         md += `\n---\n`;
         md += lastNote.contents + '\n';

         return { ContentsFormat: formats.markdown, Type: entryTypes.note, Contents: md } ;
     } else {
         return 'N/A';
     }
   type: javascript
   tags:
   - dynamic-section
   enabled: true
   scripttarget: 0
   runonce: false
   runas: DBotWeakRole
   ```
3. Add the script to the layout and then add the layout to the incident type.
4. Go to the incident to view the note information.

   You can see note information, containing the last user and date.

   ![incident-note.png](https://3790991131-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvksWgzvBZ9ZvAg4dGLrH%2Fuploads%2Fgit-blob-2df71b8c07e9c583dba66ca9a9f7ff0a99ce531b%2F60f21252bb84bd72b7ab8e722a04238ce837cd5fc834ec35d761a87cc8a447c4.png?alt=media)

</details>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-xsoar-8-on-prem/8.13/configure-cortex-xsoar/incident-configuration/incident-customization/incident-layout-customization/examples-of-using-scripts-in-incident-layouts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
