For the complete documentation index, see llms.txt. This page is also available as Markdown.
Cortex XSOAR 8 (SaaS)

Create a custom widget using a script

Create script-based widgets in Cortex XSOAR 8 SaaS.

You can use scripts in custom widgets to create dynamic widgets for more complex calculations. For examples of creating widgets using scripts, see Script-based widget examples.

Before creating a script-based widget in the Widgets Library, you need to create or upload the script to the Scripts page. In the Widgets Library, you can define the script arguments and change the visuals.

Cortex XSOAR supports JavaScript, Python and PowerShell.

Note

If you upload a script to the Scripts page, the Arguments field is automatically updated. You can then define the arguments in the widget builder. If you create a new script (without uploading) in the Scripts page, you need to add the arguments manually for them to appear in the Widgets Library when creating or editing a widget.

  1. In the Scripts page, upload or create a new script for one of the following widget types:

    • Text

    • Number

    • Duration

    • Trend

    • Chart

    • Table or list

    • Filter Data for all Widgets (Pivoting)

  2. In the Widgets Library, create a widget. For more information about creating a widget, see Create a widget using the widget builder.

  3. Select the Scripts data type and then add the script to the widget.

    (Upload script only) If you have added arguments, these appear when creating a widget. If you have not uploaded the script, you need to add the arguments manually in the Scripts page.

  4. Add the script-based widget where relevant, for example to a report, a dashboard, or an incident.

Script-based widget examples

The following are sample arguments/scripts to create a widget. After creating the widget from a script, add the widget to a dashboard or report. For more details, see Create a widget using the widget builder.

Script argument examples

To add a time stamp or a use a search query, add the following arguments to a script.

Argument
Description

demisto.args()[‘from’]

The start date of the time-stamp date range of the widget.

demisto.args()[‘to’]

The end date of the time-stamp date range of the widget.

demisto.args()['searchQuery']

The search query entered into the search bar at the top of the dashboard.

Text

In this example, create a script that queries and returns current on-line users, and displays the data in a markdown table.

In the script, type one of the following return values:

JavaScript

return executeCommand("getUsers", {online: true})[0].HumanReadable;

Python

demisto.results(demisto.executeCommand("getUsers", { "online": True })[0]["HumanReadable"])

When creating or editing the widget in Cortex XSOAR, to add a page break, type /pagebreak in the text box. When you generate a report, the widgets that follow the page break are on a separate page.

quick-definitions-pagebreak-2.png

In the dashboard, the following widget displays the on-line users:

onelineusers_widget.png

Note

(Multi-tenant) Script-based text widgets are not supported in the Main Account.

Number

This example shows how to create a single item widget with the percentage of incidents that DBot closed.

In the script, type one of the following:

JavaScript

Python

Duration

In this example, create a script that queries and returns a time duration (specified in seconds), and displays the data as a countdown clock. If using a JSON file, you must set widgetType to duration.

In the script, type one of the following return values:

JavaScript

return JSON.stringify([{ name: "", data: [120] }]);

Python

demisto.results('[{"name": "", "data": [120]}]')

The return type should be a string (any name) and an integer. The time is displayed in seconds.

After you have uploaded the script and created the widget, you can add the widget to the dashboard or report. The duration-2.jpg widget displays the time duration:

widget-time-example.jpg
Chart

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).

    Note

    A widget legend color will override a group color if it exists.

  • Groups - A nested list of groups (optional).

In this example, we show how to create a script that will query and return the trend between two sums in a pie chart.

  • Pie

  • Line

  • Bar

  • Column

Simple pie/chart

In the script, type the following return value:

JavaScript

Python

After you have uploaded the script and created the widget you can add the widget to a dashboard or report.

Two group chart

JavaScript

Python

Trend

In this example, create a script that queries and returns the trend between two sums.

In the script, type one of the following return values:

JavaScript

return JSON.stringify({currSum: 48, prevSum: 32});

Python

demisto.results({ "currSum": 48, "prevSum": 32 })

The return displays an object which compares the current sum with the previous sum.

Table or list

In this example, you need to create a script that queries and returns employee information in a table. For Table or List, if creating a JSON file, set the widgetType to table or list. When using lists, a maximum of two columns displays, the rest are ignored (do not display).

In the script, type one of the following return values:

JavaScript

Python

After you have uploaded the script and created a widget you can add the widget to a dashboard or report. The following widget displays the employee information:

widget_example_employee.png
Filter data for all widgets (pivoting)

Display filtered incident and indicator data in a widget with a bar graph

In this example, you create a filter according to type (phishing, access and IP) and then pivot to the relevant incident/indicators page. You need to add the following to the JSON or python script.

  • dataType: Pivots to the relevant page, such as Incidents page.

  • query: Filters according to the value in the relevant page. For example, for phishing, if you define ‘type:Phishing’ and the dataType:incidents, you are taken to the Incident page with the ‘type:Phishing’ filter.

  • pivot: Filters the dashboard according to data set. For example, pivot: “type:Phishing” enables you to filter data that relates to phishing in the dashboard.

In the script, type one of the following return values:

JavaScript

Python

After you upload the script and created a widget, add the widget to a dashboard or report page.

widget-customfilter-2.png

Display filtered incident and indicator data in a widget with a line graph

In this example, you create a filter according to type (phishing, access and IP) and then pivot to the relevant incident/indicators page. You need to add the following to the JSON or python automation script.

JavaScript

Python

After you upload the script and create a widget, add the widget to a dashboard or report page.

widget-pivot-line-graph.png

Last updated

Was this helpful?