> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sequentum.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Script

> Runs custom Regex, JavaScript, C#, or Python code within an Agent workflow.

The Script command runs custom Regex, JavaScript, C#, or Python code within a data extraction workflow. Use it to transform extracted data, handle complex logic, interact with APIs, or automate tasks beyond standard configuration. Scripts run in the Sequentum Cloud environment and can integrate with existing Agents; the command is located under **Other** in the command palette.

## Command properties

### Selected content

![Script selected content settings](https://mintcdn.com/sequentum/dOYM46qwxTPgqNVx/images/agents/commands/script/img-04.png?fit=max\&auto=format\&n=dOYM46qwxTPgqNVx\&q=85\&s=4199a161f824960019cd53224b8353eb)

* **When missing:** Specifies whether to **Fail**, **Warn**, **Ignore**, or **Passthrough** when the selection does not exist.
* **When hidden or disabled:** Specifies what to do when the selection is hidden or disabled on the page.
* **Selected content:** Displays the content selected by the XPath.

### Script

![Script command options](https://mintcdn.com/sequentum/dOYM46qwxTPgqNVx/images/agents/commands/script/img-02.png?fit=max\&auto=format\&n=dOYM46qwxTPgqNVx\&q=85\&s=6d58030921fe5e157bb21fd3a7c8bc44)

![Script language, code, and timeout settings](https://mintcdn.com/sequentum/dOYM46qwxTPgqNVx/images/agents/commands/script/img-05.png?fit=max\&auto=format\&n=dOYM46qwxTPgqNVx\&q=85\&s=66c2ac6fe6b155236e38452955279127)

* **Language:** Select Regex, JavaScript, C#, or Python.
* **Code:** Enter the code that the command runs.
* **Timeout:** Sets the duration within which the script is expected to complete.

For example, the following script delivers extracted data by email to recipients specified in the Agent input parameters.

```csharp theme={null}
#r System.Data.Common.dll
#r System.Data.dll
#r System.Net.dll
#r System.Net.Mail.dll
#r System.ComponentModel.TypeConverter.dll
#r System.Net.Primitives.dll
#r System.Runtime.InteropServices.dll

using System;
using System.IO;
using System.Data;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Collections.Generic;
public static bool ExportScript(ExportContext context)
{
    try
    {
        context.Log("Executing Email script");
        var data_files = context.ExportFiles.GetDataFiles();

        if (data_files.Count == 0)
        {
            context.Log("No data files found.");
            return false;
        }

        var filename = data_files[0];
        var EXPORT_DIR = Path.GetDirectoryName(filename);
        if (!File.Exists(filename))
        {
            context.Log("File does not exist: " + filename);
            return false;
        }

        if (new FileInfo(filename).Length == 0)
        {
            context.Log("File is empty: " + filename);
            return false;
        }

        context.Log("File is not empty");
        var emailBody = generateEmailBody(context, filename);
        if (string.IsNullOrEmpty(emailBody))
        {
            context.Log("Email body is empty, skipping email.");
            return false;
        }
        var dtemail = DateTime.UtcNow.ToString("MM-dd-yyyy");
        string subject = "Sequentum Cloud - Woodline Scraper: Progressive for date, " + dtemail;
        sent_email(context, subject, emailBody);
    }
    catch (Exception ex)
    {
        context.Log("Error in ExportScript: " + ex.Message);
        return false;
    }
    return true;
}
public static void sent_email(ExportContext context, string emailSubject, string emailBody)
{
    try
    {
        if (!string.IsNullOrEmpty(emailBody))
        {
            var toAddress = context.GlobalData["DistributionList"] as string;

            if (string.IsNullOrEmpty(toAddress))
            {
                context.Log("No recipient address found in DistributionList.");
                return;
            }
            context.Log("Sending email to: " + toAddress);
            // Send the email with the required parameters
            context.ScriptUtilities.SendEmail(
                toAddress,
                subject: emailSubject,
                body: emailBody,
                true,  // Treat the body as HTML
                null,    // Optional: Can be null or set a specific sender address
                null,      // Optional: CC address
                null,     // Optional: BCC address
                attachments: null, // Optional: No attachments for now
                false,  // Optional: No read receipt required
                false // Optional: Normal priority
            );
            context.Log("Email sent successfully!");
        }
        else
        {
            context.Log("Email body is empty, not sending email.");
        }
    }
    catch (Exception ex)
    {
        context.Log("Error sending email: " + ex.Message);
    }
}
public static string generateEmailBody(ExportContext context, string csvPath)
{
    StringBuilder textBody = new StringBuilder();
    List<string> emailMessageList = new List<string>();
    try
    {
        var csv_read_all = context.ScriptUtilities.LoadCsvFileIntoDataTable(csvPath);
        if (csv_read_all.Rows.Count > 0)
        {
            textBody.Append("<table border='1' cellpadding='0' cellspacing='0' width='1300'>");
            textBody.Append("<tr bgcolor='#4da6ff'>");
            context.Log("Reached checkpoint 1.");
            // Create table headers
            foreach (DataColumn column in csv_read_all.Columns)
            {
                context.Log("Entered foreach to read columns!");
                textBody.Append("<td><b>" + column.ColumnName + "</b></td>");
            }
            textBody.Append("</tr>");
            // Create table rows
            foreach (System.Data.DataRow row in csv_read_all.Rows)
            {
                context.Log("Reached foreach to read records!");
                textBody.Append("<tr>");
                foreach (var item in row.ItemArray)
                {
                    context.Log("Reached foreach to read values!"+item.ToString());
                    textBody.Append("<td>" + item.ToString() + "</td>");
                }
                textBody.Append("</tr>");
            }
            textBody.Append("</table>");
        }
        else
        {
            context.Log("No rows found in CSV file.");
        }
    }
    catch (Exception ex)
    {
        context.Log("Error generating email body: " + ex.Message);
    }
    return textBody.ToString();
    context.Log("textBody: "+textBody.ToString());
}
```

### Files

This feature lets you upload files and make them available to all commands and scripts within the Agent. Add multiple files by dragging and dropping them into **Drag files here...** or by selecting **Upload File**.

![Files available to Script commands](https://mintcdn.com/sequentum/dOYM46qwxTPgqNVx/images/agents/commands/script/img-06.png?fit=max\&auto=format\&n=dOYM46qwxTPgqNVx\&q=85\&s=92436199d087e0ca192f00ec7b93d1fd)

* **Drag and Drop Files:** Adds multiple files simultaneously by dragging and dropping them. Successfully uploaded files are accessible and visible in the user interface.
* **Upload File:** Adds multiple files simultaneously by selecting **Upload File**. Successfully uploaded files are accessible and visible in the user interface.
* **Name:** Select the file name link to open a detailed view showing the File Size, Last Modified date, and an Edit option. You can also edit the file directly from this screen.
  * **Back to Files:** Returns to the previous **Upload files** page.
  * **Edit:** Lets you modify the uploaded file.
  * **Save button:** Saves the updated file after you make changes.
  * **Cancel:** Discards your changes and keeps the file in its original state.
* **File Size:** Displays the actual size of the uploaded file.
* **Added:** Shows the date and time when the file was uploaded.
* **Delete:** Removes the uploaded file.
* **Edit:** Lets you modify an uploaded file. Selecting **Edit** opens a detailed view showing the File Size, Last Modified date, and another Edit option. You can edit the file directly from this screen.
  * **Back to Files:** Returns to the previous **Upload files** page.
  * **Edit:** Lets you modify the uploaded file.
  * **Save button:** Saves the updated file after you make changes.
  * **Cancel:** Discards your changes and keeps the file in its original state.
* **Download:** Downloads the uploaded file.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.