Vai al contenuto

Context

The Context Object

The Context object is a JavaScript object containing useful information for writing eLegere scripts. It is available in every eLegere Script through the context variable. A list of keys for this object and the corresponding values is presented below.

Abstract

Each entry lists a object of eLegere Script and their use within a function or a class.

Url string

A string containing the URL of the current eLegere Environment.

An Example:

1
2
 // Url of esi.oncloud
"https://esi.oncloud.elegere.com/"

DomainId string

A string containing the Id of the Domain in which the script will run. It identifies the eLegere Domain through a unique alpha-numeric string.

1
2
// Id of MyTicket Domain
"5e5d0d90bea69e451ad8bc1d"

TimezoneMSOffset number

1
TimezoneMSOffset: number

Number of offset milliseconds between the eLegere database time zone and UTC time. If the eLegere database changes with the daylight saving time changes, this variable will reflect the change. This permits an easy conversion between database values and UTC in order to communicate with external APIs. The User should use it with the formulas for Time and Date conversion.

An Example: If the database is using the Central European Summer Time, the shift between CEST and UTC will be 2 hours, equal to 7200000 milliseconds

SessionToken string

1
SessionToken: string

An Authentication Token required by the eLegere API. It identifies the user that is currently performing or triggering an action. This value is null when the script runs through a Scheduled Job since jobs are not associated to a specific user.

Warning

Do not manipulate in any way the SessionToken string. Such behavior can cause errors in the authentication.

ApplicationId string

1
ApplicationId: string

A string containing the id of the Application in which the script will run. It identifies the eLegere Application through a unique alpha-numeric string. This value is null when the script runs through a Scheduled Job since jobs are not associated to a specific application.

An Example:

1
2
    // Id of MyIssue App
    "82f232c0-4e03-43b2-a0d1-3b65949445e1"

A User can retrive an ApplicationId through the application's tile in the Home of eLegere. Click on the icon on the application tile. Then click on "Copy Application Id" and paste the Id in the eLegere script.

UserInfo object

1
UserInfo: object

The UserInfo object contains the details of the User who has executed (or triggered the execution) of the script. It contains only an Email key: a string containing the email address of the user that triggered the script. The whole object is null when the script is executed through a Scheduled Job since jobs are not associated to a specific user.

An Example:

1
2
3
4
{
     // Email address of the User that triggered the eLegere script
    Email: "j.doe@vesenda.com"
}

NewItem object

1
NewItem: object

A JavaScript object that represents an eLegere row after any modification on the row. Each key stands for the name of a Storage field. The value is the row's value stored in that field. The object is null if:

  • The script is executed through a Scheduled Job.
  • The script runs in the Application execution context.
  • The script runs after a PRE ROW DELETE or POST ROW DELETE trigger.

An Example:

1
2
3
4
5
6
{
    Full_Name: "John Doe",
    Birth_Date: 19780505,
    Hourly_Cost: 400,
    Id_Current_Project: 10
}

OldItem object

1
OldItem: object

A JavaScript object that represents an eLegere row before any modification on the row. Each key stands for the name of a Storage field. The value is the row's value stored in that field. The object is null if:

  • The script is executed through a Scheduled Job
  • The script runs in the Application execution context
  • The script runs after a PRE ROW INSERT or POST ROW INSERT trigger.

An Example:

1
2
3
4
5
6
7
8
9
{
    /*
    Notice how the values are different from the _NewItem_ example; this case would result from running the script as a POST ROW UPDATE action, and in this case the Hourly_Cost and Id_Current_Project were modified during the row's update.
    */
    Full_Name: "John Doe",
    Birth_Date: 19780505,
    Hourly_Cost: 300,
    Id_Current_Project: 12
 }

MasterRow object

1
MasterRow: object

A JavaScript object representing the eLegere master row related to the detail row on which the eLegere script is being executed. Each key stands for the name of a Storage field. The value is the row's value stored in that field. The object is null if:

  • The script is executed through a Scheduled Job
  • The script runs through the Application execution context.
  • The script runs through the Row execution context, but on the Application's Master table.

An Example:

1
2
3
4
5
6
7
{
    // On the Projects app, this would be the object's value when the script is executed on the "Project Team" detail
    Id_Project: 3,
    Project_Name: "Saudi Arabian Oil Co.",
    Start_Date: 2020/11/17,
    End_Date: 2022/06/16
}