Andrew Bowers Vancouver - Scheduled Script Executions and Events Flashcards
DEVELOPER TIP: Although not the primary use case, ___ ___ ___ are useful for testing server-side script logic because they can be configured to execute on demand.
DEVELOPER TIP: Although not the primary use case, Scheduled Script Executions are useful for testing server-side script logic because they can be configured to execute on demand.
DEVELOPER TIP: To run a Scheduled Script Execution on the last day of the month, configure a monthly Scheduled Script Execution set to run on day __. The Scheduled Script Execution will run on the last day of the month, even for months with fewer than __ days.
DEVELOPER TIP: To run a Scheduled Script Execution on the last day of the month, configure a monthly Scheduled Script Execution set to run on day 31. The Scheduled Script Execution will run on the last day of the month, even for months with fewer than 31 days.
Scheduled Script Executions are not associated with ___ and have no access to the ___ or ___ objects used by many other server-side script types.
Scheduled Script Executions are not associated with records and have no access to the previous or current objects used by many other server-side script types.
Scheduled Script Executions have two scripting fields:
___
___
Scheduled Script Executions have two scripting fields:
Condition
Run this script
The Condition script shown tests what? The script returns true only for ___.
If today is a weekday or weekend. Weekdays
The server-side script logic in the Run this script field executes when the Scheduled Job is triggered and the Condition script returns true.
The script shown queries the database for?
The server-side script logic in the Run this script field executes when the Scheduled Job is triggered and the Condition script returns true.
The script shown queries the database for Occasion records that match today’s month and day and logs the record numbers in the Application Log (System Logs > System Log > Application Logs).
Variables declared in the Condition script are known to the ___ ___ ___ field if permitted by the rules of JavaScript scope.
Variables declared in the Condition script are known to the Run this script field if permitted by the rules of JavaScript scope.
NOTE: If the Scheduled Script Execution includes a Condition script, the Condition script must set the answer variable to true for the Run this script field’s script to execute, even when using the ___ ___ button to test the Scheduled Script Execution.
NOTE: If the Scheduled Script Execution includes a Condition script, the Condition script must set the answer variable to true for the Run this script field’s script to execute, even when using the Execute Now button to test the Scheduled Script Execution.
Where would I find the outputs of the following line in a scheduled script that was executed:
gs.info(‘This is the text’);
System Logs > System Log > Application Logs
I’m not sure that this is true if the application isn’t scoped (this was done in the needit application via studio)
What is the following solution doing:
var rightNow = new GlideDateTime();
var dueSoon = new GlideRecord(‘x_58872_needit_needit_task’);
dueSoon.addQuery(‘due_date’,’>=’,rightNow);
dueSoon.addQuery(‘due_date’,’<’,gs.hoursAgo(-24));
dueSoon.addQuery(‘state’,’!=’,3);
dueSoon.query();
This code gets NeedIt records that are due in the next 24 hours that are not already in a state of complete.
This solution uses the GlideSystem hoursAgo() method. When passed a positive number, the method looks into the past. When passed a negative number, the method looks into the future. It may seem counterintuitive for a negative number to reference the future. The method is hoursAgo(), which is why positive numbers are in the past. Two hours ago is a positive number.
Events are an indication in ServiceNow that something notable has occurred. Events can be generated by server-side scripts, workflows, ServiceNow processes, or by user actions such as:
____
____
____
____
Events are an indication in ServiceNow that something notable has occurred. Events can be generated by server-side scripts, workflows, ServiceNow processes, or by user actions such as:
Impersonating a user
Logging in
Viewing a record
Modifying a record
Each event is an entry in an event queue and not an action. Unless logic is created to respond to events, nothing happens with an event after it is generated. Responses can be:
___ ___
___ ___ (server-side script)
Each event is an entry in an event queue and not an action. Unless logic is created to respond to events, nothing happens with an event after it is generated. Responses can be:
Email notification
Script Action (server-side script)
The generalized process to work with events is:
_____
_____
_____
The generalized process to work with events is:
Add event to the Event Registry (not needed if you generate an already registered event).
Generate the event.
Respond to the event.
There are two ways to generate events:
_____
_____
There are two ways to generate events:
Server-side script
Workflow Create Event activity
The ___ and ___ methods are part of the GlideSystem server-side API. Use the ___ and ___ methods to generate events in server-side scripts.
The eventQueue() and eventQueueScheduled() methods are part of the GlideSystem server-side API. Use the eventQueue() and eventQueueScheduled() methods to generate events in server-side scripts.
The eventQueue() method inserts an event in an event queue. The eventQueue() method is typically passed four parameters but can also take an optional 5th parameter:
The eventQueue() method inserts an event in an event queue. The eventQueue() method is typically passed four parameters but can also take an optional 5th parameter:
Event name. Enclose the event name in quotes.
GlideRecord object, typically current but can be any GlideRecord object from the event’s table.
Any value that resolves to a string. This is known as parm1 (Parameter 1). Can be a string, variable that resolves to a string, or method that resolves to a string.
Any value that resolves to a string. This is known as parm2 (Parameter 2). Can be a string, variable that resolves to a string, or method that resolves to a string.
(Optional) Name of the queue to manage the event.
The logic that responds to an event has access to the passed in GlideRecord object, parm1, and parm2.
Consider this case:
gs.eventQueue(‘x_60157_employee_spe.employeeOccasion’,current,current.number,gs.getUserName());
Why would current.number be passed when current is already included as the record parameter?
The logic that responds to an event has access to the passed in GlideRecord object, parm1, and parm2.
Consider this case:
gs.eventQueue(‘x_60157_employee_spe.employeeOccasion’,current,current.number,gs.getUserName());
Notice that the gs.eventQueue method is passed the current object and that parm1 is current.number. Since current was passed as part of the event, passing current.number in parm1 seems redundant. Why, then, would one do this? The parm1 and parm2 parameters appear in their resolved form in the Event Log. Having access to a record identifier, such as the record number, in the logging information can be useful for troubleshooting.
DEVELOPER TIP: Use ___ and ___ for parm1 and parm2 if no other values are required to see which user triggered the event in the event log.
DEVELOPER TIP: Use gs.getUserName() and gs.getUserID() for parm1 and parm2 if no other values are required to see which user triggered the event in the event log.
When would one use the GlideSystem eventQueueScheduled() method instead of gs.eventQueue
Use the GlideSystem eventQueueScheduled() method to generate an event with an expiration.
What is being displayed below:
Created: Date and time of the event for the locale of the machine running the ServiceNow instance.
Name: Name of the event.
Parm1: Value passed when the event was generated.
Parm2: Value passed when the event was generated.
Table: Database table acted on by this event.
Processed: Date and time the event was processed. This time reflects the locale of the machine running the ServiceNow instance.
Processing duration: Time taken to process this event in milliseconds.
Queue: Processor queue name.
These are the values that can be seen in the event log
There are two possible ways to respond to events:
There are two possible ways to respond to events:
Email Notification
Script Action
Script Actions are event handlers; server-side script logic that executes in response to events.
Script actions have two scripting fields:
___
___
Script actions can access two useful objects:
___
___
Script actions have two scripting fields:
Condition Script: JavaScript condition for Script to execute. The Script only loads if the condition tests true.
Script: Server side JavaScript logic to execute if the condition tests true.
Script actions can access two useful objects:
event
current
The Script field, but not the Condition field, has access to the ___ ___. To use parm1 or parm2, reference them as properties on the ___ ___.
The Script field, but not the Condition field, has access to the event object. To use parm1 or parm2, reference them as properties on the event object:
if(event.parm2 != ‘admin’){ }
What would be the purpose of a custom event queue?
Applications that create a large volume of events and/or events that take a long time to process should use a custom queue.
Populate the Queue field for the event in the Event Registry to define a custom queue. Use only lowercase letters, no spaces, and no special characters except underscore (_).