Pre-Job Event
The pre-job event initiates before the job begins executing queries. The specifics about the job (including the name of the job, the source, the destination, and so on) are available as input parameters that you can use to make logical choices within the event script. You can also push attribute values in the output item that can be used later during the execution of the job.Creating Environment Variables
You can create environment variables in the pre-job event script and add them to the job execution. The following example creates a currentTimeStamp variable with the current timestamp and pushes the out item with that value to the job:Using Environment Variables in the REPLICATE Query
You can use environment variables that are pushed to the job in different ways within the REPLICATE query. To reference an environment variable, surround theenv:attribute with curly braces (). The following example sets the value of currenttimestamp to the new column DateUpdated:
Post-Job Event
The post-job event initiates after the job finishes executing queries. The input item includes the results of the job execution, which you can use to call other operations.Triggering a Job Execution
You can configure a post-job event to trigger the execution of another job. For example, the following code snippet executes Job2 after the current job finishes running queries. You can also extend this example by using theapi:if keyword to execute Job2 only if the current job succeeds.
In this example, the job.WorkspaceId attribute identifies the workspace that contains the target job. When you want to trigger a job within the same workspace, set this attribute to default or specify the workspace’s name. When you want to trigger a job in another workspace, provide the name of that workspace. The Insert Snippet option in the Event editor includes the job.WorkspaceId attribute automatically with the value set to default.
This attribute is required in these cases:
- The workspace for both jobs is the same workspace but is not the default workspace.
- The initiating job and the target job belong to different workspaces.
If you omit this attribute in such cases, the API call can fail. When a failure occurs, does not display an error message during the save operation or when the job runs. The job status appears as successful, even though the post-job event did not execute as expected. However, an error is recorded in the application logs. To verify whether a post-job event actually succeeded, review the logs after your job runs.
Extending the Example Scripts
The code snippets in this section are just a few examples of what is possible by using APIScript. The APIScript language is computationally complete, enabling it to manage complex business logic. You can use other APIScript keywords to control execution flow and more. The script includes many enhancements and built-in operations that make processing and automation easy. For example, APIScript facilitates tasks such as sending an email, moving a file, and so on. You can also pass additional input values that are specific to the operation. Examples-
The
appSendEmailoperation accepts several additional input items (such as body text, attachments, and SSL/TLS properties). You provide these items by using theapi:setkeyword. -
You can call any of the built-in operations in an event and also make calls to the API by using the
api:callkeyword.