Special Variables
  • 3 Minutes to read
  • Dark
    Light
  • PDF

Special Variables

  • Dark
    Light
  • PDF

Article summary

There are some special variables that contain information injected into a script if the script was executed by an event trigger.

Event Triggered Executed Special Variables

The following variables are available when a script is executed by an event trigger:

Variable Name

Type

Description

$ABVAREvent

JObject

Contains information about the event that triggered the script, such as the object name, the workspace id, the date/time, and the id and name of the person who triggered the script.

Tip

This variable is provided as a JObject type, so use the .ToString() function on it to create a JSON string, which could then be piped to the ConvertFrom-Json cmdlet to create a PowerShell Hashtable object.

$ABVARObject

JObject

The raw inbound JObject instance. The Get-InboundObjectInstance cmdlet converts this object for you to provide a ready-to-use PowerShell object and would be better to use in most situations. This variable may come in handy if that cmdlet happens to fail for some reason.

Tip

This variable is provided as a JObject type, so use the .ToString() function on it to create a JSON string, which could then be piped to the ConvertFrom-Json cmdlet to create a PowerShell Hashtable object.

$ABVARObjectType

JObject

The fully qualified type of the inbound object instance. Useful for inspecting or comparing types for triggers that may have multiple return types based on the $ABVAREventAction variable.

Tip

This variable is provided as a JObject type, so use the .ToString() function on it to create a JSON string, which could then be piped to the ConvertFrom-Json cmdlet to create a PowerShell Hashtable object.

$ABVARScriptId

String

Provides the id of the script that is currently being executed.

$ABVAREventAction

String

Provides the event action. Some objects, like Task, have “sub-actions” that are stored in this variable that can be checked to determine a course of action and even require different return types in before-save trigger scenarios. Check out the tasks attached to event triggers section in the Concepts: Tasks & Task Forms article for more details on how this variable can be used.

Example Usages

Example script that provides output from all special variables. Note that the output will indicate that the variable is unavailable if you try to execute this script manually:

if ($null -ne $ABVAREvent) {
    Write-Output "ABVAREvent is available ($($ABVAREvent.GetType()))"
    
    $ABVAREvent.ToString()
    
    Write-Output ""
} else {
    Write-Output "ABVAREvent is not available"
}

if ($null -ne $ABVARObject) {
    Write-Output "ABVARObject is available ($($ABVARObject.GetType()))"
    
    $ABVARObject.ToString()
    
    Write-Output ""
} else {
    Write-Output "ABVARObject is not available"
}

if ($null -ne $ABVARObjectType) {
    Write-Output "ABVARObjectType is available ($($ABVARObject.GetType()))"
    
    $ABVARObjectType.ToString()
    
    Write-Output ""
} else {
    Write-Output "ABVARObjectType is not available"
}

if ($null -ne $ABVARScriptId) {
    Write-Output "ABVARScriptId is available ($($ABVARScriptId.GetType()))"
    
    $ABVARScriptId
    
    Write-Output ""
} else {
    Write-Output "ABVARScriptId is not available"
}

if ($null -ne $ABVAREventAction) {
    Write-Output "ABVAREventAction is available ($($ABVAREventAction.GetType()))"
    
    $ABVAREventAction
    
    Write-Output ""
} else {
    Write-Output "ABVAREventAction is not available"
}

Sample output:

ABVAREvent is available (Newtonsoft.Json.Linq.JObject)
{
  "Payload": {
    "Id": 28641,
    "DisplayValue": "UPDATE"
  },
  "Origin": null,
  "Zone": 1,
  "Action": 2,
  "Object": "Contact",
  "WorkspaceId": 922,
  "CreatedOn": "2024-10-24T19:53:55.2958292+00:00",
  "CreatedBy": {
    "Id": "4d004c9a-03e3-073c-0f96-b0556bf6735d",
    "DisplayValue": "Taylor Thompson"
  },
  "Message": "Contact 'UPDATE' (28641) updated"
}

ABVARObject is available (Newtonsoft.Json.Linq.JObject)
{
  "ContactId": 28641,
  "FirstName": "Aaron",
  "LastName": "Gerard",
  "FullName": "Aaron Gerard",
  "EmailAddress": "agerratymn@merriam-webster.com",
  "NameAndEmailAddress": "Aaron Gerard <agerratymn@merriam-webster.com>",
  "PhoneNumber": null,
  "TimeZoneIdentifier": "Central Standard Time",
  "EnableNotifications": false,
  "AllowPortalAccess": false,
  "IsFavorite": false,
  "NumberOfProjects": 0,
  "CreatedByFullName": "Taylor Thompson",
  "CreatedById": "4d004c9a-03e3-073c-0f96-b0556bf6735d",
  "CreatedOn": "2023-02-23T13:38:16.2183354+00:00",
  "CreatedBy": null,
  "LastUpdatedByFullName": "Taylor Thompson",
  "LastUpdatedById": "4d004c9a-03e3-073c-0f96-b0556bf6735d",
  "LastUpdatedOn": "2024-10-24T19:53:55.1653167+00:00",
  "LastUpdatedBy": null,
  "Fields": []
}

ABVARObjectType is available (Newtonsoft.Json.Linq.JObject)
AgilityBlue.ViewModels.Workspace.ContactViewModel, AgilityBlue.ViewModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

ABVARScriptId is available (string)
a54d24fd-b120-40e7-a7bf-0487c6a8dba7

ABVAREventAction is available (string)
UPDATE


What's Next