work flows

123
PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information. PDF generated at: Tue, 21 Oct 2014 13:16:53 PST Workflows Automating Processes Using Graphical Workflow

Upload: dumitrache-veronica

Post on 04-Sep-2015

96 views

Category:

Documents


24 download

DESCRIPTION

Work Flows

TRANSCRIPT

  • PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information.PDF generated at: Tue, 21 Oct 2014 13:16:53 PST

    WorkflowsAutomating Processes Using GraphicalWorkflow

  • 1Introduction

    Workflow Overview

    OverviewThe Graphical Workflow engine automates multi-step processes. Each workflow has a sequence of activities, such asgenerating records or running scripts, and transitions between them based on conditions.For each step in the workflow:1. An activity is processed; the behavior determined by the activity occurs.2. When the action completes, the workflow checks each of the activity's conditions.3. For each matching condition, the workflow follows the transition to the next activity.When the workflow runs out of activities, the workflow is complete.

    Using Workflows Workflow ActivitiesStreamline processes with workflows. Create custom activities and utilize the full potential of workflows.

    Workflow Administration Workflow ExamplesTailor workflow exactly the way you want them. Discover new ways to use workflows.

    Workflow ValidationValidate workflows before you publish them.

    Workflow Validation Workflow Validation Report Workflow Validators

  • Using the Graphical Workflow Editor 2

    Using the Graphical Workflow Editor

    OverviewThe Graphical Workflow Editor is an interface for defining and modifying workflows by arranging and connectingactivities to power processes.

    Workflow Interface ToolsTo open the Graphical Workflow Editor, navigate to Workflow > Workflow Editor.

    Workflow Title BarThe title bar in the graphical workflow editor contains controls for displaying and managing workflows. When aworkflow is loaded or created, the title bar appears at the top of the canvas.

    The title bar provides these controls: New: Click New to create a new workflow. Open: Click Open to load an existing workflow. Properties definition : Click the properties icon to open the current workflow's Properties definition. Name: The title bar displays the name of the workflow. State: Possible states for a workflow are Checked out by and Published. Start : Click the Start icon to test run the workflow. Validate : Click the Validate icon to test your workflow prior to publication. Validation detects potential

    problems that can prevent the workflow from publishing or cause the workflow to fail. For more information seeWorkflow Validation. Validation is available with the Calgary release.

    Debug : Click the Debug icon to open the JavaScript debug window.

  • Using the Graphical Workflow Editor 3

    Workflow Menu

    Click the gear icon to display the workflow action menu.

    The following menu options are available: New Workflow: Creates a new workflow. Open Existing: Opens an existing workflow. Copy: Creates a duplicate workflow with a different name. Checkout: Creates a personal Workflow Version, which can be edited. Click Checkout to open an existing,

    published workflow for edit. This option only appears on the menu when the current workflow has beenpublished.

    Publish: (not pictured) Makes the personal Workflow Version public, over-writing the current PublishedWorkflow Version. Published workflows cannot be edited until checked out. This option only appears on themenu when the current workflow is checked out.

    Delete: Deletes the Workflow. You cannot delete workflows that have contexts associated with them. Set Inactive: Marks the workflow inactive, ensuring that it will not be used. Expand Transitions: Redraws the transitions so that they don't overlap when they leave the activity condition. Validate Workflow: Runs validation tests on your workflow prior to publication which detect potential problems

    that can prevent the workflow from publishing or cause the workflow to fail. For more information see WorkflowValidation. Validation is available with the Calgary release.

    Collapse Transitions: (not pictured) Redraws the transitions to they overlap when they leave the activitycondition.

    Properties: Opens the Workflow Properties, which define the workflow's attributes. Edit Inputs: Opens the Inputs form, which defines the variables the workflow can accept when used as a

    subflow. For more information, see Using Subflows. Edit Stages: Defines the stages of the Workflow.

  • Using the Graphical Workflow Editor 4

    Activity MenuLoading the workflow also populates the activity menu on the right-hand side of the Workflow Editor:

    The arrow icon collapses ( ) or expands ( ) the activity menu.The menu is populated with a collapsible tree of activities that can be dragged into the workflow. For moreinformation, see Using Workflow Activities.When a workflow is not loaded, the activity menu displays these options. Trying to create a new Workflow?: Click to create a new workflow Looking for a new workflow?: Click to open an existing workflow

  • 5Creating Workflows

    Creating a Workflow

    OverviewWorkflows are created using the Graphical Workflow Editor.If the workflow is being designed as part of an update set process, review the document Moving Workflows withUpdate Sets before creating the workflow.

    Creating a WorkflowTo create a new workflow, navigate to Workflow > Workflow Editor and click New.There are three major steps to creating a workflow:1. Defining Workflow Properties2. Adding Workflow Activities3. Publishing the Workflow

    Defining Workflow PropertiesWorkflow properties are defined when a new workflow is created. To change the property settings, open theworkflow actions menu ( ) and select Properties or click the Properties icon ( ) beside the workflow name.The following properties can be defined for a workflow:

    Field Description

    Name A unique name to identify the workflow. Users cannot create a workflow with the same name as an existing workflow startingwith the Eureka release.

    Table The table for the workflow to run on. Workflows that run on specific tables can still interact with other tables. Select Global[global] to run the workflow on all tables.

    Note: All users who edit the workflow must have access to the necessary tables and domains.

    If conditionmatches

    The workflow runs when the conditions evaluate to true. Select -- None -- to only run the workflow on a schedule.

    Order The order workflows run, depending on the order of other workflows. Evaluated from lowest to highest; the workflow with thelowest order that matches conditions runs.

    Condition A condition builder for specifying workflow conditions that trigger the behavior specified in the If Condition Matches field.

    Expected time If specified, used in place of the Delivery Time value from a catalog item. This field is available for workflows that run on theservice catalog Request [sc_request] table. Workflows cannot calculate delivery time based on the activities they contain, so it isimportant to manually specify the expected time.

    Stage field The field on the table that should be updated with the stage information. If this value is not specified, the default stage field forthe table is used. For more information, see Using Workflow Stages.

    StageRendering

    The renderer to use when displaying stage icons on a form or list view. For more information about renderers, see RenderingWorkflow Stages.

  • Creating a Workflow 6

    Stage order The order of workflow stages when you view a workflow field in a list. Select Computed to let the workflow engine compute thestage order from the order of execution in the workflow. Select User Specified to use the Order field from that workflow'sstages.

    Max activitycount

    The maximum number of activities performed by the workflow. Used to prevent infinite loops; if the maximum is reached, theworkflow is canceled. If this field is blank, there is no maximum.

    Published Check box to indicate whether the workflow has been published. Automatically set by the Publish action in the workflow actionsmenu.

    Checked out When the workflow was checked out. Automatically set by the Checkout action in the workflow actions menu.

    Checked out by The user who has this workflow checked out. This value is automatically set by the Checkout action in the workflow actionsmenu.

    Description A description of the workflow.

    Run after bus.rules run

    Check box indicating whether the workflow runs after the applicable business rules run. A workflow with this check box set toFalse is known as a default workflow, or a deferred workflow if True. This check box should be selected if the workflow isintended to generate approvals.

    Personalizing Workflow PropertiesThe Workflow Properties form cannot be personalized from inside the graphical workflow editor. To personalize theWorkflow Properties form, navigate to Workflow > Workflow Versions, select a workflow, and personalize theform.

    Adding Workflow ActivitiesActivities determine the functionality of the workflow. When they are created, all workflows contain Start and Endactivities.To add a workflow activity, drag it from the Activities menu into the workflow body, and populate the WorkflowActivity form that appears. For more information, see Using Workflow Activities.

    Validating the WorkflowWhen the workflow is complete, validate it prior to publishing. Workflow validation tests the workflow for potentialissues that might cause it to fail, such as missing subflows or disconnected transitions. A workflow validation reportlists the results of each validator and provides enough information to trace problems and make any changes that arenecessary. Workflow validation is available starting with the Calgary release.

    Publishing the Workflow

    After the workflow is complete, open the workflow actions menu ( ) and select Publish. The workflow is nowactive, and is used according to the defined properties. To edit a published workflow, open the workflow actionsmenu and select Checkout. Note that publishing a new version of a workflow does not change any workflowcontexts that were created before the new version was published.

  • Creating a Workflow 7

    Editing Published WorkflowsAfter the workflow is published, the Checkout option appears in the workflow actions menu. Checking out aworkflow creates a new workflow version assigned to the user that checked out the workflow. If the user is in adifferent domain than the published workflow, the new workflow version is created in that user's domain startingwith the Eureka release.Users cannot check out or delete workflows that are associated with a read-only application file starting with theEureka release.

    ExamplesBecause of the flexibility of workflows, you can create many different types of workflows. Following is a list ofworkflow examples specific to certain processes: Workflow Example for Service Levels Workflow Example for the Service Catalog Workflow Example for Problem Management Workflow Example for Change Management Advanced Approval Workflow (Part 1) Advanced Approval Workflow (Part 2)

    Using Workflow Stages

    OverviewWorkflow stages are used to provide summary-level feedback about the progress of a workflow. Stage icons displaythe status of each activity as it is being driven by a workflow. The system updates a Stage field, defined in theworkflow properties, to indicate the workflow's progress through the possible stage values. The workflow Stage fieldcan contain values from any of the fields available on the table selected for the workflow. If the selected Stage fieldis a choice list field, then all the choices from that field are available as stage values for the workflow.

    Note: An updated method for managing workflow stages as a set is available starting with the Dublin release. For information aboutgrouping and reusing stages, see Workflow Stage Sets.

    How Stage Values Are DerivedStage values are derived from combining the following sources in the system: Choices for Stage column: Choices defined for the column selected as the Stage column for the workflow. Default stages for table: Stages defined in the Stage Default [wf_stage_default] table for the table selected. Workflow specific stages: Applied only to the workflow for which they were defined in the Workflow Stage

    [wf_stage] table. Stage values in existing records: Values from the designated Stage column in the table assigned to the workflow

    are inherited from existing records.If the stage field for a workflow is the table column named Stage, then the progress of the workflow appears in anylist view that contains the Stage column.

  • Using Workflow Stages 8

    Stage values shown in the list views are accompanied by the state, based on the workflow activities being executed.If an activity has a stage specified for it, and the activity is currently active in the workflow, then the stage is shownwith a state of In progress. Similarly, if the activity is in the Pending or Completed state, the stage reflects thisstate.

    ExampleIf the workflow table is Request Item [sc_req_item], then the stage field is automatically set to the Stage column ofthat table and cannot be changed. The following stage values for the request item are displayed in a choice list fromthe Dictionary Entry [sys_dictionary] table: Waiting for Approval Fulfillment DeliveryIn addition, the Request Item [sc_req_item] table has two default stages (Workflow > Default Stages). Request Cancelled CompletedWhen you edit available activity stages on the workflow canvas, the list displays these five stage values.

    The following diagram depicts the process the system uses to gather stage values from the Request Item[sc_req_item] table to populate the Stages list in workflow activities.

  • Using Workflow Stages 9

    Note: When using a table other than Request Item [sc_req_item], the workflow designer must select a Stage field for the workflow tohave stages.

    Using Workflow Stages1. Navigate to Workflow > Workflow Editor.2. Click New.3. In the Workflow Properties form, if the table is not Requested Item [sc_req_item], select a field to display stages

    in the Stage field property.Available fields depend on the table selected for the workflow.

    4. After assigning a list of stages to the workflow, you can set a stage value in any of the workflow activities thatprovide a Stage field in their dialog box. Setting a stage value in a workflow activity tells the workflow engine toassign that stage to the record associated with the workflow context when the activity is encountered during a run.

    When an activity starts with a specified stage, the platform updates the Stage field with the current value. Inworkflows run against the Requested Item [sc_req_item] table, the sc_req_item.stage field is definedas a workflow type field.When displaying the stages for a workflow on the Requested Item [sc_req_item] table, the stage state is basedon the state of the workflow activities. If an activity has a stage specified for it, and the activity is currentlyactive in the workflow, then the stage is shown with an In progress state. Similarly, if the activity is in thePending or Completed state, the stage reflects this state.

    5. To edit the workflow-specific stages for an existing workflow, click the gear icon in the header bar and selectEdit Stages. Again, these stage values are combined with the choices, defaults, and existing values.

  • Using Workflow Stages 10

    ExampleTo optimize the use of stages, you can assign a stage to multiple activities in a workflow. For example, yourworkflow uses the following activities to create tasks:1. Get approval2. Order equipment3. Receive equipment4. Add equipment to CMDB5. Set up equipment6. Install software7. Configure software8. Deliver to userThe available stages might be the following: Approval Order Configure DeliverA good practice is to assign stages to the approvals as follows:1. Get approval (Stage = Approval)2. Order equipment (Stage = Order)3. Receive equipment (Stage = Order)4. Add equipment to CMDB (Stage = Order)5. Set up equipment (Stage = Configure)6. Install software (Stage = Configure)7. Configure software (Stage = Configure)8. Deliver to user (Stage = Deliver)When activity 2, 3, or 4 is active, the Stage display shows that the Order stage is In progress.

  • Using Workflow Stages 11

    Adding Default StagesServiceNow uses stage sets to determine default workflow stages for a table, starting with the Eureka release.To add default stages:1. Create a new stage set.2. Navigate to Workflow > Default Stages (by table).3. Click New.4. Select a stage Set.5. Select a corresponding Table.6. Click Submit.The stages in the specified stage set will be automatically included in any new workflows on that table.

    Click the plus to show previous version information

    1. Navigate to Workflow > Default Stages (by table).2. Click New.3. Fill in the fields, as appropriate (see table).

    Field Description

    Table The name of the table for which default stages are defined.

    Name The name of the default stage as it appears in workflow fields.

    Value The value of the default stage when referencing the stage from elsewhere in the system, such as in a script.

    Duration The default duration for the stage.

    Order The order in which default stages apply, from lowest to highest, if more than one applies.

    Adding Stages to an Existing Workflow1. Navigate to Workflow > Workflow Editor.2. Open an existing workflow and check it out.3. Open workflow action menu from the gear icon and select Edit Stages.4. In the Workflow Stages list, click New.5. Complete the form as described on this page.

    Do not use a Name or Value field value that already exists in the base system.

  • Using Workflow Stages 12

    6. Click Submit.

    Adding a Stage to a Workflow ActivityAfter a workflow has defined stages, the workflow author can add the stages to corresponding workflow activities.1. Navigate to Workflow > Workflow Editor.2. Open an existing workflow and check it out.3. Double click on an activity.4. In the Stage field, select the stage to display when the workflow reaches the activity.5. Click Update.

    Translating StagesA workflow author can define language-specific text for a stage. The instance must already have a language packinstalled. Translated stages are available starting with the Eureka release.Language-specific text appears in workflow fields displayed in a list, workflow stage sets, and the workflow editorfor users with that language selected. Language-specific text does not automatically appear when displaying stageson a form. To translate stages on a form, add translated text to the workflow field choices.A workflow author can add translated text for any language enabled on the instance. For example, to translateworkflow stages into French:1. Set the interface language to French.2. Navigate to Workflow > Workflow Editor.3. Click Open.4. Select a workflow.5. Open the workflow actions menu and select Edit Stages.6. Edit the Name field for each stage and enter the text to display to French users.

    Do not change the Value field.7. Confirm the workflow stage displays the French text.8. Set the selected language to English.9. Navigate back to the list of workflow stages.10. Confirm the workflow stage displays the English text.Alternatively, to translate stages for multiple workflows at once, you can directly edit the Workflow Stages[wf_stage] table. For example, to translate workflow stages from multiple workflows into French:1. Set the interface language to French.2. Enter wf_stage.list in the navigation filter3. Edit the Name field for each stage and enter the text to display to French users.

    Do not change the Value field.

  • 13

    Workflow Activities

    Using Workflow Activities

    OverviewWorkflow activities are the individual actions the Workflow performs as it executes.

    Note: Run the workflow validator tool prior to publishing to detect problems that can cause a workflow to hang, such as missing ordisconnected transitions. Validation is available with the Calgary release.

    Adding an Activity to the WorkflowTo add an activity to the workflow, find the activity in the Activity Menu and drag it into the workflow. Theappropriate Activity form appears.All activity records have a Table value. If this value is Global, the activity is available for use with any workflowregardless of the Table selected in the workflow properties. Activities that identify a specific table appear in theActivity Menu only if the workflow Table matches or extends the table identified in the activity.For information on how to define different types of activities, locate the appropriate Activity article: Approval Activities Condition Activities Notification Activities Orchestration Active Directory Activities Orchestration Activities PowerShell Activities Timer Activities Task Activities Utility Activities VMware Activities Orchestration Amazon EC2 Activities Using Subflows Puppet Activities

  • Using Workflow Activities 14

    Duplicating an ActivityTo duplicate an existing activity, right-click the existing activity and select Copy Activity:

    The activity automatically duplicates:

    Viewing Activity DescriptionsServiceNow provides inline descriptions for workflow activities to help workflow designers understand how to useeach activity (Dublin). To modify activity descriptions, navigate Workflow > Activity Definitions and edit theDescription field.To view an activity description from the workflow canvas, point to the icon for an activity.

    To view more information on the ServiceNow Wiki using Context-Sensitive Help, double-click an activity on thecanvas and click the help icon ( ) in the Activity Properties window.

  • Using Workflow Activities 15

    Managing Transitions

    Adding TransitionsIf the activity is dragged onto a transition line between two activities so that the line highlights blue, it is insertedbetween the two activities in the Workflow sequence. Run the workflow validation tool prior to publishing to detectmissing or disconnected transitions that can cause a workflow to hang. Validation is available with the Calgaryrelease.These two activities are linked by a transition:

    Dragging an activity between them creates this sequence:

    The transitions are updated automatically to reflect the new sequence.To add a transition to an existing activity, drag from the yellow tab at the right of the Activity Condition to the nexttask:

    Multiple transitions can be drawn from the same Activity Condition to execute concurrently.

  • Using Workflow Activities 16

    Removing TransitionsTo remove a transition, click to highlight it:

    Press Delete.

    Custom TransitionsControls on the Approval - User activity enable an administrator to add additional workflow transitions to theactivity other than the default transitions of Approved or Rejected. Transitions defined in this fashion do notbecome a permanent feature of the Approval - User activity. After a new transition is configured, that transition mustbe applied manually to subsequent instances of the activity, where desired. For instructions, see Custom Transitionsfor the Approval - User Activity.

    Managing ConditionsActivities come with default conditions that determine which transition(s) are followed. For instance, the followingactivity has two conditions, Approved and Rejected:

    Creating a New ConditionCustom conditions can be created on activities, using a simple javascript condition check. To create a new condition,right click the activity and select Add Condition:

  • Using Workflow Activities 17

    The following fields determine the condition's behavior.

    Field Input Value

    Name The label that is displayed on the Workflow.

    Else If checked, the transition only runs if no other transitions run.

    Event If checked, the transition runs if a particular event (defined with the Event Name field) is detected.

    Event Name An event to trigger the conditoin.

    Skip during Generate If checked, the Generate Activity does not follow this transition to generate approvals or tasks.

    Condition A Javascript condition check. The following variables are available:

    current

    The current record that the workflow is running against.

    activity.result

    The result value set by the activity upon completion.

    activity

    The Workflow Executing Activity (wf_executing) record. Used for advanced condition checks.

    activity.vars

    The variables associated with the Workflow Executing Activity record. Used for advanced condition checks.

    Editing Condition PropertiesTo edit the properties of an existing condition:1. Open the workflow.2. Checkout the workflow.3. Double-click the condition whose properties you want to edit.4. Change the condition properties. See Creating a New Condition for field descriptions.

    Sample condition properties

    5. Click Update.

    Reordering Conditions

    Conditions can also be reordered as they appear on the WorkflowActivity by right-clicking the activity and selecting ReorderConditions:

  • Using Workflow Activities 18

    Using the Activity Result ValueThe result value specified by an activity controls which condition the activity transitions through. Use the resultvalue as part of the Condition field of an activity condition. For example, from an Approval - User activity, aCondition field containing activity.result == 'rejected' would cause the activity to transitionthrough that condition if the approver rejected the approval. Result values are set in the Script field of the activitydefinition.

    Ending the Workflow

    End ActivityOnce the Workflow reaches the End Activity, the workflow will be complete. This is true even if there are still activebranches of the workflow in progress.For example, take the following workflow:

    If Branch B tasks 1 and 2 are completed, the workflow is marked complete, even if Branch A tasks are notcompleted:

    To ensure that both branches are completed, add a Join activity to resolve the branch. When one branch reaches thejoin, the workflow will wait for the other branch:

    When both branches are complete, the workflow now reaches the end:

  • Using Workflow Activities 19

    The "Incomplete" condition will only be fired if one of the branches cannot be completed.

    Canceling WorkflowExecuting workflows can be cancelled using a script action. This can be helpful in cases where workflow needs to becancelled in response to an event, or where a user needs to manually cancel a workflow.The method for canceling a workflow is documented here.

    Understanding Workflow Activity ElementsEach activity can specify a number of elements that control the behavior of the activity or are controlled by theactivity. Not all activities specify all possible elements. The ServiceNow Wiki provides reference documentationabout workflow activities that includes which elements each activity specifies.

    Element Description

    Results The possible activity.result values. The activity result usually determines which condition the activity transitionsthrough.

    ScratchpadEntries

    Scratchpad variables the activity depends on to run, or variables the activity writes to the scratchpad.

    Input Variables Values that control the behavior of the activity. Fields to set these values appear on the Activity Properties form when adding anew activity to a workflow. See Using Activity Variables for more information.

    Conditions Determines which transition the activity follows after completing. See Managing Conditions for more information.

    States Determines how the workflow handles the record being executed.

  • Approval Activities 20

    Approval Activities

    OverviewApproval Activities allow workflows to generate and manage approvals while driving a record to fulfillment.Note that these activities are only available when the workflow is defined to run on a table which extends Task, withthe exception of the Approval - User and Approval Action, which are available globally.

    Note: If using Approval Activities to generate approvals, make sure to select the Run after bus. rules run workflow property.Otherwise, the business rules that handle non-workflow approvals conflict with the workflow.

    Approval - GroupThe Approval - Group activity creates approval records for each member of a specified group. The group approvalis approved or rejected based on the user approvals, according to the logic specified in the Wait For field.For provisioning workflows that require approvals in the Calgary release, select from the following groups,depending on your virtualization product. Only one member of either approval group is required to approve arequest. VMware Approvers EC2 Approvers Virtual Provisioning Cloud Administrators

    Result ValuesThe workflow designer can assign a result value using activity.result from within a script field of the activity. Bydefault, the result value is the final approval disposition. This disposition depends on the approval actions take by theapprovers and the approval conditions specified in the Wait for or When Anyone Rejects fields. Possible resultvalues are: Approved Rejected Deleted Cancelled

    Input Variables

  • Approval Activities 21

    Field Description

    Condition Conditions which, if met, cause the Group Approval to be generated. If the conditions are not met, the approval is skipped.

    Groups The groups whose approval will be requested. A particular group can be selected, or the tree icon can be used to select a group field from the currentrecord. A user approval for each member of the group is automatically created when a Group approval record is created. If no group is selected, theactivity automatically sets the approval to Approved.

    Wait for A choice between different approval logics to determine which individual approvals or rejections result in approval or rejection of the activity'sapproval. Options are:

    An approval from each group - Any user from each group can approve and the first approval from each group causes the activity to completewith a result of approved (see below for how a rejection is handled)

    An approval from any group - Any user from any group can approve and the first approval from any group causes the activity to completewith a result of approved

    An approval from everyone from all groups - All users from all groups must approve to cause the activity to complete with a result ofapproved (see below for how a rejection is handled)

    First response from each group - The first approval or rejection from any user in each group is used to indicate the state of the group approval(see below for how a rejection is handled)

    First response from any group - The first approval or rejection from any user in any group causes the activity to complete with a result ofapproved or rejected

    Condition based on script - Each time a user approves or rejects, the Approval Script is called to determine if the activity should complete.

    Indicate what happens when any user rejects their approval request. Options are:

    Reject the approval - Immediately complete the activity with a result of rejected Wait for other responses before deciding - Wait until we get other responses before making an approval or rejection decision.

    This allows users to change their mind until a decision is made. In addition, if Wait for is set to An approval from any group then a singleapproval will cause the activity to complete with a result of approved even if one or more users from other groups reject.

    Whenanyonerejects

    A choice between different approval logics to determine which individual rejections result in rejection of the activity's approval. Options are:

    Reject the approval - Immediately complete the activity with a result of rejected Wait for other responses before deciding - Wait until we get other responses before making an approval or rejection decision. This allows

    users to change their mind until a decision is made.

    Note: If Wait for is set to Anyone to approve, then a single approval causes the activity to complete with a result of approved, evenif one or more users reject.

    Advanced Check this checkbox to write a script for determining additional users to request approvals from.

    Due datebased on

    The due date fields are used to determine the values to use for setting Expected Start Time and Due Date for the approval. The type determines howthe due date is computed:

    A user specified duration - The duration is based on a user specified value A relative duration - The duration is calculated from a relative duration (such as End of Next Business Day) A date/time or duration field - The duration is based on the value of a field on the current record Script - The duration is returned by a script

    Duration The user specified duration when the type is A user specified duration.

    Relativeduration

    The relative duration when the type is A relative duration.

    Due datefield

    The date/time or duration field when the type is A date/time or duration field.

    Due datescript

    The script that sets 'answer' to the number of seconds for the duration.

    Schedulebased on

    A choice of where to draw a schedule from, to calculate the duration. If a schedule is provided, the duration will only be considered for times thatare specified on the schedule. For example, if the time is 2 hours and the duration begins at 4:00pm on a schedule that is 8am - 5pm, then theduration ends at 9:00am the next day on the schedule. Options are:

    A specified schedule A schedule field

  • Approval Activities 22

    Schedule The specific schedule to use when Schedule based on is A specific schedule.

    Schedulefield

    The field in current that identifies the schedule to use when Schedule based on is A schedule field.

    Time zonebased on

    A choice of where to draw the time zone from, to use when calculating the duration. Options are:

    A specific time zone A time zone field

    Time zone The specific time zone to use when Time zone based on is A specific time zone.

    Time zonefield

    The field in current that identifies the time zone to use when Time zone based on is A time zone field.

    Additionalgroupsscript

    If the Advanced checkbox is checked, this script is called to determine any additional group approvals to be created. The script needs to set thevariable 'answer' to a comma-separated list of group ids or an array of group ids to add as approver groups. For example:

    answer = []; answer.push('id1'); answer.push('id2');

    Approvalscript

    If the Wait for variable is set to Condition based on script this script is called to determine how to handle an approval or rejection. The scriptneeds to set the variable 'answer' to , 'approved' or 'rejected' to indicate the overall approval status for this approval. This script is responsible forsetting the approval state for each group that is part of this approval activity before returning the overall approval state for all of the group(s).

    When called, the following variables are available to the script:

  • Approval Activities 23

    Overall for all of the groups that are part of this approval activity:

    counts.total = total number of groups that are part of this approval

    counts.approved = # of groups that approved so far

    counts.rejected = # of groups that rejected so far

    counts.requested = # of groups that are pending approval

    counts.not_requested = # of groups that are not pending approval

    counts.not_required = # of groups that approval is not required

    And for each group:

    groups[group_id].total = total number of users that are part of this group's approval

    groups[group_id].approved = # of users that approved so far

    groups[group_id].rejected = # of users that rejected so far

    groups[group_id].requested = # of users that are pending approval

    groups[group_id].not_requested = # of users that are not pending approval

    groups[group_id].not_required = # of users that approval is not required

    groups[group_id].approvalIDs[state] = array of user ids that are at the specified approval state

    Note: Iterate the groups using:

    for (var id in groups) { var group = groups[id]; ... group.total ... }

    Note: Get group object using the following code (to get things like the group name being iterated on):

    var objGroup = fncGetGroupObj(id);var strGroupName = objGroup.name;

    function fncGetGroupObj(sidGroupApproval){ var objGroupApproval = new GlideRecord('sysapproval_group'); objGroupApproval.get(sidGroupApproval); var objGroup = new GlideRecord('sys_user_group'); objGroup.get(objGroupApproval.assignment_group.sys_id); return objGroup;}

    ConditionsThe following conditions determine which transition comes after this activity.

    Condition Description

    Approved The users from the groups have approved the request based on the Wait for rules.

    Rejected The users from the groups have rejected the request based on the Wait for rules.

  • Approval Activities 24

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine starts the run function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activity, was cancelled.

    Error A JavaScript error occurred. Review the logs for error details.

    Approval - UserThe Approval - User activity creates one or more individual user approvals.

    ResultsThe result value is the final approval disposition. This disposition depends on the approval actions take by theapprovers and the approval conditions specified in the Wait for or When Anyone Rejects fields. Possible resultvalues are: Approved Rejected Deleted Cancelled

    Input Variables

    Field Description

    Condition Conditions which, if met, cause the Individual Approval to be generated. If the conditions are not met, the approval is skipped.

    Users The users for the approval. You must specify all required users before starting the workflow. After starting the workflow, newly addedapprovals do not affect the workflow context. Use the tree icon to select user reference fields from the current record to createapprovals, such as ${assigned_to}. If no user is selected, the activity automatically sets the approval to Approved.

    ApprovalColumn

    A string field for the name of the approval field on the table the workflow is running on. The default value is approval, which is thefield on the Task table.

    Note: Use the field's name, not its label.

    ApprovalHistory

    A string field for the name of the field that records approval history on the table the workflow is running on. The default value isapproval_history, which is the field on the Task table.

    Note: Use the field's name, not its label.

    Groups Groups whose members should also receive approvals. Note that this is different than the Approval - Group activity, which creates aGroup Approval in addition to the individual approvals. The tree icon can be used to select group reference fields from the currentrecord to create approvals, such as ${assignment_group}.

    Wait for A choice between different approval logics to determine which individual approvals result in approval of the activity's approval.Options are:

    Anyone to approve - Any user can approve and the first approval causes the activity to complete with a result of approved. Everyone to approve - All users must approve (see below for how a rejection is handled) First response from anyone - The first approval or rejection from any user causes the activity to complete Condition based on script - Each time a user approves or rejects, the Approval Script is called to determine if the activity should

    complete.

  • Approval Activities 25

    Whenanyonerejects

    A choice between different approval logics to determine which individual rejections result in rejection of the activity's approval.Options are:

    Reject the approval - Immediately complete the activity with a result of rejected Wait for other responses before deciding - Wait until we get other responses before making an approval or rejection decision.

    This allows users to change their mind until a decision is made.

    Note that if Wait for is set to Anyone to approve then a single approval will cause the activity to complete with a result of approvedeven if one or more users reject.

    Advanced Check this checkbox to write a script for determining additional users to request approvals from.

    Due datebased on

    The due date fields determine the values to use for the Expected Start Time and Due Date of the approval. The type determines how thedue date is computed:

    A user specified duration - The duration is based on a user specified value A relative duration - The duration is calculated from a relative duration (such as End of Next Business Day) A date/time or duration field - The duration is based on the value of a field on the current record Script - The duration is returned by a script

    Duration The user specified duration (when the type is A user specified duration)

    Relativeduration

    The relative duration (when the type is A relative duration)

    Due datefield

    The date/time or duration field (when the type is A date/time or duration field)

    Due datescript

    The script that sets 'answer' to the number of seconds for the duration

    Schedulebased on

    A choice of where to draw a schedule from, to calculate the duration. If a schedule is provided, the duration will only be considered fortimes that are specified on the schedule. For example, if the time is 2 hours and the duration begins at 4:00pm on a schedule that is 8am- 5pm, then the duration ends at 9:00am the next day on the schedule. Options are:

    A specified schedule A schedule field

    Schedule The specific schedule to use when Schedule based on is A specific schedule.

    Schedulefield

    The field in current that identifies the schedule to use when Schedule based on is A schedule field.

    Time zonebased on

    A choice of where to draw the time zone from, to use when calculating the duration. Options are:

    A specific time zone A time zone field

    Time zone The specific time zone to use when Time zone based on is A specific time zone.

    Time zonefield

    The field in current that identifies the time zone to use when Time zone based on is A time zone field.

    Additionalapproversscript

    If the Advanced checkbox is checked, this script is called to determine any additional user approvals to be created. The script needs toset the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers. Forexample:

    answer = []; answer.push('id1'); answer.push('id2');

  • Approval Activities 26

    ApprovalScript

    If the Wait for variable is set to Condition based on script this script is called to determine how to handle an approval or rejection.The script needs to set the variable 'answer' to [nowiki][/nowiki], 'approved' or 'rejected' to indicate the approval status for thisapproval. When called, the following information is available:

    counts.total = total number of users that are part of this approval counts.approved = # of users that approved so far counts.rejected = # of users that rejected so far counts.requested = # of users that are pending approval counts.not_requested = # of users that are not pending approval counts.not_required = # of users that approval is not required

    ConditionsThe following conditions determine which transition comes after this activity. For instruction on creating customtransitions for this activity, see Custom Transitions for the Approval - User Activity.

    Condition Description

    Approved The users approved the request based on the Wait for rules.

    Rejected The users rejected the request based on the Wait for rules.

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine starts the run function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    Approval ActionThe Approval Action activity perform an approval action on the current task. Use this activity to mark the currenttask record as approved or rejected.

    Note: When an Approval Action activity is used to mark a task approved, the activity marks all pending approvals as No LongerRequired. This activity behaves differently from Set Values or Run Script when used to set the Approval field's value.

  • Approval Activities 27

    ResultsThe result value of the activity is the final approval disposition selected by the approver. The result value can beApproved or Rejected. A workflow designer can assign a result value using the activity.result variablefrom within a script field of the activity.

    Input Variables

    Field Description

    Action The action to perform on the task. Options are:

    Mark task approved Mark task rejected Mark task requested Disregard pending approvals

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine starts the run function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    Approval CoordinatorThe Approval Coordinator activity is used as a container for one or more Approval - User, Approval - Groupand Manual Approval activities. The Approval Coordinator is then responsible for waiting for the approvalactivities that are contained within it before deciding of it should complete with a result of approved or rejected.When the Approval Coordinator activity completes, all pending approvals that were created by any of theApproval Coordinator approval activities are immediately set to No Longer Required. If a single user is called asan approver twice by the same workflow, such as when a single user is both a product approver and an executiveapprover, any approvals for that user after the first are skipped.

    Result ValuesThe result value of the Approval Coordinator activity depends on the approval actions taken by the approvers andthe approval conditions specified in the Wait for field. Possible result values are: Approved Rejected Deleted Cancelled

  • Approval Activities 28

    Input Variables

    Field Description

    Wait for Indicate what to wait for to indicate that the approval activity is approved or rejected. Options are:

    Any child activity to be approved - Any child activity (User, Group or Manual Approval) that completes with a result of approvedcauses the Approval Coordinator activity to complete with a result of approved

    All child activities to be approved - All child activities of the Approval Coordinator activity must complete with a a result ofapproved to cause the Approval Coordinator activity to complete with a result of approved (see below for how a rejection ishandled)

    The first approval or rejection from any child activity - The first child activity that completes with a result of approved orrejected causes the Approval Coordinator activity to complete with the same result. Indicate what happens when any of the childactivities completes with a result of rejected. Options are:

    Reject the approval - Immediately complete the Approval Coordinator activity with a result of rejected Wait for other responses before deciding - Wait until we get other responses from other child activities before making an

    approval or rejection decision.

    This allows users to change their mind until a decision is made. In addition, if Wait for is set to Any child activity to approve then asingle child activity completion with a result of approved will cause the Approval Coordinator activity to complete with a result ofapproved even if other child activities have completed with a result of rejected.

    Approvalscript

    If the Wait for variable is set to Condition based on script this script is called to determine how to handle an approval or rejection. Thescript needs to set the variable 'answer' to , 'approved' or 'rejected' to indicate the overall approval status for this approval. When called,the following variable is available to the script:

    counts.total = total number of child approval activities that are part of this approval

    counts.approved = # of child approval activities that approved so far

    counts.rejected = # of child approval activities that rejected so far

    counts.requested = # of child approval activities that are pending approval

    ConditionsThe following conditions determine which transition comes after this activity:

    Condition Description

    Approved The users have approved the request based on the Wait for rules.

    Rejected The users have rejected the request based on the Wait for rules.

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine starts the run function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

  • Approval Activities 29

    GenerateThe Generate activity immediately creates task or approval records from any task or approval activities placed afterthe Generate activity in the workflow execution path. By default, the workflow does not create any tasks orapprovals until it reaches them in the workflow. The Generate activity does the following:1. Follows all transitions through the workflow to each activity. For each activity:

    If it is a Task activity, creates the Task and sets: The State to Pending The Expected Start Date The Due Date

    If it is an Approval activity, creates the Approvals and sets: The Approval State to Not Requested The Expected Start Date The Due Date

    Expected Start Dates and Due Dates are calculated based on the Expected Durations of all of the tasks and approvalsbetween the Generate activity and the activity being updated. In the case of a branched path (between a Branch andJoin activity), the longer duration will be used for any post-branch activities.The Generate activity can be used more than once, and any tasks or approvals will be refreshed with updatedinformation. This is useful in situations where the list of approvers or other important information is still editablewhile the workflow is in process, and it may be necessary to update/correct the generated approvals or tasks.To exclude a set of activities from the Generate activity, check the Skip during generate checkbox on anyCondition and its transitions will not be followed during the generate process. By default, the following conditionshave the Skip during generate check box checked: Rejected (for any of the approval activities) No condition of If activity Continue condition of Turnstile activity Incomplete condition of Join activity

    Input Variables

    Field Description

    Generateapprovals

    If checked, approvals are created when running the Generate activity. If not checked, the approvals are used to compute theirestimated duration but no approvals are created.

    Generate tasks If checked, tasks are created when running the Generate activity. If not checked, the tasks are used to compute their estimatedduration but no tasks are created.

    StatesThe activity state tells the workflow engine what to do with the activity.

  • Approval Activities 30

    State Description

    Executing The workflow engine starts the run function of the activity.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Example

    In this example, the following approvals are generated: Approval-2 Approval-3Approval-4 is skipped since the Rejected Condition of Approval-3 has Skip during generate checked.Here is an example of using the Generate Activity that describes the Expected Start and Due Dates:

    In this example, if the Generate activity is run on Jan 1, 2011. The following Expected Start Dates and Due Dateswould be set for the generated Tasks:

  • Approval Activities 31

    Task Expected Start Date Reason Due Date

    Task 1 (1 day) Jan. 1, 2011 Jan. 2, 2011

    Task 2 (1 day) Jan. 2, 2011 Task 1 is 1 day Jan. 3, 2011

    Task 3 (2 days) Jan. 1, 2011 Jan. 3, 2011

    Task 4 (1 day) Jan. 3, 2011 Task 3 is 2 days Jan. 4, 2011

    Task 5 (1 day) Jan. 4, 2011 Task 4 ends the latest before the Join Jan. 5, 2011

    Notice that Task 5 starts on Jan. 4, 2011 since the longest path (based on Due Dates) to the Join is Task 3/Task 4.

    Manual ApprovalsThe Manual Approvals activity watches and manages any approvals that users add manually outside of theworkflow process. If there are no pending manual approvals when this activity executes, the activity willimmediately complete with a result of approved. This activity does not create approval records.Use this activity to pause the workflow when a user adds a manual approval to a record with an associated workflow.The workflow waits for the approval to be closed before proceeding.

    Result ValuesThe workflow designer can assign a result value using activity.result from within a script field of the activity. Bydefault, the result value of the activity is the final approval disposition determined by the approval actions take bythe approvers. Possible result values are: Approved Rejected Deleted Cancelled Error

    Input Variables

    Field Description

    Wait for Indicate what to wait for to indicate that the approval activity is approved or rejected. Options are:

    Any manual user or group approval - Any user can approve and the first approval causes the activity to complete with aresult of approved

    All manual user or group approvals - All users must approve (see below for how a rejection is handled) First response from any manual approval - The first approval or rejection from any user causes the activity to complete

    When anyonerejects

    Indicate what happens when any user rejects their approval request. Options are:

    Reject the approval - Immediately complete the activity with a result of rejected Wait for other responses before deciding - Wait until we get other responses before making an approval or rejection decision.

    This allows users to change their mind until a decision is made. In addition, if Wait for is set to Anyone to approve then a singleapproval will cause the activity to complete with a result of approved even if one or more users reject.

  • Approval Activities 32

    ConditionsThe following conditions determine which transition comes after this activity:

    Condition Description

    Approved The users approved the request based on the Wait for rules.

    Rejected The users rejected the request based on the Wait for rules.

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine starts the run function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    RollbackThe Rollback activity transitions to an earlier activity, and updates all approvals and tasks executed after that point.Approvals are reset to Not Requested, and tasks are reset to Open. The workflow then resumes from that earlieractivity. Rollback updates all activities that have executed between the rollback and the transitioned to activity,including those not directly joined by transition lines. As a result, processing might rollback farther than expected,because activities do not always execute in a predictable order. The best practice for using this activity is forworkflows that have only one rollback. Using this activity with multiple rollbacks can result in task and approvalactivities being left in an unresolved state. For a detailed discussion of the differences between Rollback andRollback To, see Selecting a Rollback Activity.

    Note: The Rollback activity does not reset Manual Approval activities. When the workflow moves through the Manual Approvalstage the second time, it automatically approves or rejects based on the approval's state. If the Manual Approval activity is followedby a Rollback directly, this causes a loop.

    The Rollback activity is deprecated starting with the Eureka release. Use the Rollback To activity instead.

  • Approval Activities 33

    Input Variables

    Field Description

    Comment field The rollback comment is written to this field in the current task.

    Comment This comment is written to the Comment field in the current task and is typically used to indicate that a rollback has occurred.

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine starts the run function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    Rollback ToThe Rollback To activity transitions directly to the activity specified by the transition line arrow and has morepredictable results than the Rollback activity. Rollback To determines which activities to reset based on the actualworkflow sequence (transition line attachments) of activities between itself and the transitioned to activity, not theexecution order. Rollback To then marks all the Approvals that have transitioned between the rollback and thetransitioned to activity as Not Yet Requested and the Tasks as either Open or Pending. Use the Rollback Toactivity for all workflows in which multiple rollbacks are required. Rollback To has no variables or conditions.For a detailed discussion of the differences between Rollback and Rollback To, see Selecting a Rollback Activity.For sample workflows that use Rollback To, see Designing Workflows with Rollback To.

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine starts the run function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

  • Condition Activities 34

    Condition Activities

    OverviewCondition activities provide conditional branching and logical operation functionality for workflows.

    IfThe If activity checks a condition or script to determine if a Yes or No transition should be taken. If workflowcreator specifies both the Condition and the Advanced script, both must evaluate successfully for activity to takethe Yes transition.

    ResultsThe workflow designer can assign a result value using activity.result from within the Script field on the activityrecord. By default, the result value of the activity is the final result of the condition or script specified. Possible resultvalues are: Yes No

    Input VariablesThe following variables determine the behavior of the activity:

    Field Description

    Condition If specified and the current record matches the condition, the Yes transition is taken.

    Advanced andScript

    To specify a script, check the Advanced checkbox. You may then enter a script that is evaluated. If your script sets the variable'answer' to 'yes', then the Yes transition is taken. Otherwise, the No transition is taken.

    ConditionsThe following conditions determine which transition comes after this activity:

    Condition Description

    Yes Taken when the condition, if specified, matches and the Advanced script, if specified, returns yes.

    No Taken when either the condition does not match or the Advanced script, if specified, returns no.

    StatesThe activity state tells the workflow engine what to do with the activity.

  • Condition Activities 35

    State Description

    Executing The workflow engine knows to start the onExecute function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    SwitchThe Switch activity performs a check to determine if the value of a passed field or variable is equivalent to one ofseveral case values. The switch activity behavior is similar to a switch statement in Java.When creating a switch activity, select a Variable or Field to check against activity conditions for a matching fieldvalue. When the value passed in this variable or field matches the value defined in the Condition field of the activitycondition, the workflow progresses through that activity condition.

    ResultsThe workflow designer can assign a result value using activity.result from within a script field of the activity. Bydefault, the variable or field selected in the Variable or Field activity variable determines the possible result values.

    Input Variables

    Field Description

    Type Select Variable or Field as the type of value to check against available conditions. This selection sets the label and availableoptions for the other field.

    Variable orField

    Select the source of the value compared against the switch activity conditions. The field label and available options depend on theType selection.

    Variable: select any service catalog variable. Field: select any field from the Table defined in the workflow properties.

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine knows to start the onExecute function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

  • Condition Activities 36

    ExampleYou can create a switch activity that sets different field values on an incident based on the Assignment group of theincident record.

    The Field selected is the incident Assigned to field.

    If the value of the Assigned to field of the workflow-triggering incident is Service Desk or Field Services, theworkflow populates values on the incident record before continuing. If the Assigned to value is Hardware, theworkflow continues without populating any field values.

  • Condition Activities 37

    Wait for conditionThe Wait for condition activity causes the workflow to wait at this activity until the current record matches thespecified condition. The workflow evaluates the wait for condition each time the current record is updated. Use thisactivity to pause a workflow indefinitely until a particular criteria is met by a record update. To pause a workflow fora timed duration see Timer Activities.

    ResultsThe workflow designer can assign a result value using activity.result from within a script field of the activity. Theactivity transitions when the result value is true.

    Input VariablesThe following variables determine the behavior of the activity:

    Field Description

    Condition The workflow is paused at this activity until this condition matches the current record.

    Condition script If specified, the workflow is paused at this activity until this script sets the answer variable to true.

    StatesThe activity state tells the workflow engine what to do with the activity.

  • Condition Activities 38

    State Description

    Executing The workflow engine knows to start the onExecute function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    ExampleThis example service request workflow uses the Wait for Condition activity to allow users to manually addadditional tasks to the request item at a certain stage in the process.1. Define the workflow as seen below:

    2. Open up the Wait for condition and paste the following into the Condition script:

    var gr_tsk = new GlideRecord("sc_task");gr_tsk.addQuery('request_item', current.sys_id);gr_tsk.addQuery('state', '!=', '3');gr_tsk.addQuery('state', '!=', '4');gr_tsk.addQuery('state', '!=', '7');gr_tsk.addQuery('wf_activity', '');gr_tsk.query();if (gr_tsk.next()) { answer = false;} else { answer = true;}

  • Condition Activities 39

    This script will check for all tasks associated with the request item that are not Closed complete, Closedincomplete, or Closed skipped, and that are not governed by workflow. If there are any, then the workflow willwait.Note: the wf_activity field is disabled in the dictionary, so is not visible in the form or list views. But it is still validto use in a script.1. Next, create a business rule that forces the workflow to rerun executing activities when a task that is not governed

    by workflow is closed. Without this business rule the workflow will stay at the Wait for condition activity untilthe request item is updated.

    Business Rule Definition:

    Table: Catalog taskWhen: afterUpdate: trueCondition: current.wf_activity.isNil() && current.active.changesTo(false)Script:

    forceReqItemUpdate();

    function forceReqItemUpdate() { var wf = new Workflow(); var ri = new GlideRecord("sc_req_item"); if (ri.get(current.request_item)) { wf.runFlows(ri, 'update'); }}

    Wait for WF EventThe Wait for WF Event activity causes the workflow to wait at this activity until the specified event is fired. Usethis activity to wait for another activity to fire an event.

    ResultsThe workflow designer can assign a result value using activity.result from within a script field of the activity. Thisactivity transitions when the specified event fires.

    Input VariablesThe following variables determine the behavior of the activity:

    Field Description

    Wait for Event An event name to trigger the workflow.

  • Condition Activities 40

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine knows to start the onExecute function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    Notification Activities

    OverviewNotification Activities allow workflows to notify users of events that occur during the workflow.

    Create EventThe Create Event adds an event to the event queue, but does not immediately fire the event. The event processortypically processes the the event within one minute. This activity triggers any business rules or email notificationsthat would normally be triggered by the event.

    Results Finished: the activity added the event to the event queue.

    Input Variables

    Field Description

    Event name The name of the event to create.

    Parameter 1 The first parameter of the event.

    Note: if this parameter is a string value, it must be within quotes (" ").

    Parameter 2 The second event parameter.

    Note: if this parameter is a string value, it must be within quotes (" ").

  • Notification Activities 41

    NotificationThe Notification activity sends an email or SMS message to specified users or groups.

    Input Variables

    Field Description

    To The users that will be recipients of the email.

    To(groups)

    The members of the groups that will be recipients of the email.

    Subject The subject line of the email.

    Message The email body that is sent.

    Advanced If checked, the To (script) is called to specify additional recipients of the email.

    To (script) If Advanced is checked, this script is called and should set the variable 'answer' to a comma-separated list of user or group sys_ids thatyou want to add as recipients of the email.

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The workflow engine knows to start the run function of the activity.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

  • Timer Activities 42

    Timer Activities

    SLA Percentage TimerThe SLA Percentage Timer activity pauses the workflow for a duration equal to a percentage of an SLA. Aworkflow must run on the Task SLA table to use this activity.

    Results Complete: the activity successfully reached the specified duration. Cancelled: the activity or workflow was canceled before the timer reached the specified duration.

    Input Variables

    Field Description

    Percentage The duration to pause the workflow for, as a percentage of the current SLA.

    StatesThe activity state tells the workflow engine what to do with the activity.

    State Description

    Executing The activity is in this state very briefly while initializing, after which it immediately changes to waiting.

    Waiting The workflow engine ignores the activity until the SLA reaches the specified percentage. The engine then re-invokes the activity totransition the workflow to the next activity.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    TimerThe Timer activity pauses the workflow for a set period of time. This duration can be an absolute time value or arelative value based on a defined schedule. To pause a workflow indefinitely until a condition is met, see wait forcondition.

    Results Complete: the activity successfully reached the specified duration. Cancelled: the activity or workflow was canceled before the timer reached the specified duration.

  • Timer Activities 43

    Input VariablesThe following variables determine the behavior of the activity:

    Field Description

    Timer basedon

    How the timer duration is computed. Options are:

    A user specified duration - The duration is based on a user specified value A relative duration - The duration is calculated from a relative duration (such as End of Next Business Day) A date/time or duration field - The duration is based on the value of a field on the current record. Script - The duration is returned by a script.

    Duration The user specified duration (when the type is A user specified duration)

    Relativeduration

    The relative duration (when the type is A relative duration)

    Field The date/time or duration field (when the type is A date/time or duration field)

    Script The script that sets 'answer' to the number of seconds for the duration

    Wait Modifies the timer duration. Only available for relative durations and date/time or duration field types. Options are:

    The full duration - No modification of the calculated duration

    A % of the duration - The duration is adjusted by multiplying the number of seconds by the (Percentage / 100)

    Some time before - The duration is adjusted to occur the specified time before the calculated duration Some time after - The duration is adjusted to occur the specified time after the calculated duration

    Percentage The Wait percentage value when Wait is A % of the duration.

    Time before The modifier time value when Wait is Some time before.

    Time after The modifier time value when Wait is Some time after.

    Schedulebased on

    Where to draw the schedule from to calculate the duration. If a schedule is provided, the duration will only be considered for timesthat are specified on the schedule. If the duration is 2 hours and begins at 4:00pm on a schedule that is 8am - 5pm, then it ends at9:00am the next day. Options are:

    This workflow's schedule A specific schedule A schedule field

    Schedule The specific schedule to use when Schedule based on is A specific schedule.

    Schedule field The field in current that identifies the schedule to use when Schedule based on is A schedule field.

    Time zonebased on

    Where to draw a time zone from that is used when calculating the duration. The time zone may be based on:

    A specific time zone A time zone field

    Time zone The specific time zone to use when Time zone based on is A specific time zone.

    Time zonefield

    The field in current that identifies the time zone to use when Time zone based on is A time zone field.

    StatesThe activity state tells the workflow engine what to do with the activity.

  • Timer Activities 44

    State Description

    Executing The Timer activity is in this state very briefly while initializing, after which it immediately changes to waiting.

    Waiting The workflow engine ignores the activity until the timer reaches the specified duration. The engine then re-invokes the activity totransition the workflow to the next activity.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    ExampleYou can use a timer activity to pause the workflow until the end of the business day.

    In this example, the script evaluates the time between the now variable and the eod variable. The eod variable isdefined, in 24 hour time, as 4:00 PM. The script then sets the answer variable to the difference between thesevariables, in seconds, and logs a message.

    // get now and calc end of day (4:00pm)

    var now = new Date();

    var eod = new Date();

    eod.setHours(16);

    eod.setMinutes(0);

    eod.setSeconds(0);

    answer = (eod.getTime()- now.getTime()) * 1000;

    workflow.debug( 'Timer will fire @: ' + eod + ' ' +

  • Timer Activities 45

    (answer/60000) + ' minutes from now' );

    Using Multiple Timer Activities in One WorkflowWorkflow timer activities store data independently of each other in an activity-specific scratchpad (Eureka).Previously, all timer activities in a workflow accessed a single, shared scratchpad which could lead to conflicts whenadding multiple timer activities to one workflow.Timer scratchpads entries hold these values: workflow.scratchpad.endTime workflow.scratchpad.realStartTime workflow.scratchpad.retroactiveSecsLeft

    Task Activities

    OverviewTask activities create and modify tasks. Note that these activities are only available when the workflow is defined torun on a table which extends Task.

    Add WorknoteThe Add Worknote activity adds text to the Worknotes field of the current incident record. A workflow must runon the Incident table to use this activity.

    Input Variables

    Field Description

    Work note The text to add to the incident record.

    Attachment NoteThe Attachment Note activity adds a comment to a journal field containing a link that points towards an attachment.Attachments added to a record from this activity do not appear at the top of a record, but open a URL containing thecontent. This activity allows the use of irregular HTML tags to reference attachments, specifically the [code] tag.Entries in a journal field that use irregular HTML do not work if theglide.ui.allow_deep_html_validation property is true (It is set to false by default).

  • Task Activities 46

    Results Finished: the activity added the attachment to the record.

    Input VariablesThe following variables determine the behavior of the activity:

    Field Description

    Field A journal field to note the attachment. Options are:

    none (defaults to Work Notes) Additional Comments Work Notes

    AttachmentName

    The name of the attachment in the URL. In versions at Calgary or later, this name appears on the attachment at the top of theform.

    AttachmentData

    The body of the attachment. This is the content of the attachment, formatted in a .txt file. It can be in plain text or use variables toextract specific data from a table.

    Catalog TaskThe Catalog Task activity creates a service catalog task record. A user must complete the catalog task. This activityis only available for workflows running on the Catalog Request Item [sc_req_item] table.

    ResultsYou can assign a result value using activity.result from within a script field of the activity. The final Statevalue of the catalog task record determines the result value for the Create Task activity. Possible result values are: Closed complete Closed incomplete Closed skipped Deleted Cancelled

    Input VariablesThe following variables determine the behavior of the activity:

    Field Description

    Priority The Priority that is assigned to the task.

    Wait forcompletion

    If checked, the workflow activity waits for the task to complete before continuing. If not checked, the task is created but theworkflow proceeds.

    Due date basedon

    The due date fields are used to determine the values to use for setting Expected Start Time and Due Date for the task. The typedetermines how the due date is computed:

    A user specified duration - The duration is based on a user specified value A relative duration - The duration is calculated from a relative duration (such as End of Next Business Day) A date/time or duration field - The duration is based on the value of a field on the current record Script - The duration is returned by a script

    Duration The user specified duration when the type is A user specified duration.

    Relativeduration

    The relative duration when the type is A relative duration.

  • Task Activities 47

    Due date field The date/time or duration field when the type is A date/time or duration field.

    Due date script The script that sets 'answer' to the number of seconds for the duration.

    Schedulebased on

    Where to draw a schedule from to be used when calculating the duration using one of the following options. If a schedule isprovided, the duration will only be considered for times that are specified on the schedule. For instance, if the duration is 2 hoursand begins at 4:00pm on a schedule that is 8am - 5pm, then the duration ends at 9:00am the next day.

    Options are:

    A specified schedule A schedule field

    Schedule The specific schedule to use (when Schedule based on is A specific schedule)

    Schedule field The field in current that identifies the schedule to use (when Schedule based on is A schedule field)

    Time zonebased on

    Where to draw the time zone from to calculating the duration. The time zone may be based on:

    A specific time zone A time zone field

    Time zone The specific time zone to use when Time zone based on is A specific time zone.

    Time zonefield

    The field in the current task that identifies the time zone to use when Time zone based on is A time zone field.

    Task valuefrom

    The values used to create the task may either come from:

    Fields - a predefined set of fields including Fulfillment group, Assigned to, Short description and Instructions Template - an existing template for the selected task table Values - values that you specify using a Set Values widget

    Fulfillmentgroup

    The group that is responsible for completing the task.

    Assigned to The user that is responsible for completing the task.

    Shortdescription

    A short description for the task.

    Instructions Any task instructions these are written to the task Description field.

    Advanced If checked, the Advanced script is called to allow for additional task values to be set.

    AdvancedScript

    Set additional values for the task in this script. Use the variable 'task' when setting additional values. This script is run after the taskvalues are set using the Fields, Template or Values you have specified. For example: task.short_description =current.short_description;

    Variables onTask Form

    A slush-bucket of optional Catalog variables to include. The variables here are displayed in the Catalog Task form in a field calledVariable Editor. If no variables are defined in the field on the Catalog Task activity, the Variable Editor field in the CatalogTask form is not visible.

    StatesThe activity state tells the workflow engine what to do with the activity. Possible state values are:

  • Task Activities 48

    State Description

    Executing The workflow engine knows to start the onExecute function of the activity.

    Waiting The workflow engine ignores the activity until a specific event to restart the activity is fired.

    Finished The activity finished running. See the result value for the outcome of the activity.

    Cancelled This activity, or the workflow that contains this activty, was cancelled.

    Error A JavaScript error occured. Review the logs for error details.

    Create TaskThe Create Task activity generates a record on any of the tables that extend Task [task].

    ResultsYou can assign a result value using activity.result from within a script field of the activity. By default, thefinal State value of the task record determines the result value for the Create Task activity. Possible result values are: Closed complete Closed incomplete Closed skipped Deleted Cancelled

    Input VariablesThe following variables determine the behavior of the activity:

    Field Description

    Task type The type of task to create. Select from any Task Table.

    Priority The Priority that is assigned to the task.

    Wait forcompletion

    If checked, the workflow activity waits for the task to complete before continuing. If not checked, the task is created but theworkflow proceeds.

    Due datebased on

    The due date fields are used to determine the values to use for setting Expected Start Time and Due Date for the task. The typedetermines how the due date is computed:

    A user specified duration - The duration is based on a user specified value A relative duration - The duration is calculated from a relative duration (such as End of Next Business Day) A date/time or duration field - The duration is based on the value of a field on the current record Script - The duration is returned by a script

    Duration The user specified duration when the type is A user specified duration.

    Relativeduration

    The relative duration when the type is A relative duration.

    Due date field The date/time or duration field when the type is A date/time or duration field.

    Due datescript

    The script that sets 'answer' to the number of seconds for the duration.

  • Task Activities 49

    Schedulebased on

    Where to draw a schedule from to be used when calculating the duration using one of the following options. If a schedule isprovided, the duration will only be considered for times that are specified on the schedule. For instance, if the duration is 2 hoursand begins at 4:00pm on a schedule that is 8am - 5pm, then the duration ends at 9:00am the next day.

    Options are:

    A specified schedule A schedule field

    Schedule The specific schedule to use (when Schedule based on is A specific schedule)

    Schedulefield

    The field in current that identifies the schedule to use (when Schedule based on is A schedule field)

    Time zonebased on

    Where to draw the time zone from to calculating the duration. The time zone may be based on:

    A specific time zone A time zone field

    Time zone The specific time zone to use when Time zone based on is A specific time zone.

    Time zonefield

    The field in the current task that identifies the time zone to use when Time zone based on is A time zone field.

    Task valuesfrom

    The values used to create the task may either come from:

    Fields - a predefined set of fields including Fulfillment group, Assigned to, Short description and Instructions Template - an existing template for the selected task table Values - values that you specify using a Set Values widget

    Fulfillmentgroup

    The group that is responsible for completing the task.

    Assigned to The user that is responsible for completing the task. See Workflow Assignments for more information on using a workflow toassign tasks.

    Shortdescription

    A short description for the task.

    Instructions Any task instructions these are written to the task Description field.

    Task template A template that is used to fill in values for the task.

    Set values A widget that is used to specify values for any fields of the task.

    Advanced If checked, the Advanced script is called to allow for additional task values to be set.

    AdvancedScript

    Set additional values for the task in this script. Use the variable 'task' when setting additional values. This script is run after the taskvalues are set using the Fields, Template or Values you have specified. For example: task.short_description =current.short_description;

    StatesThe activity state tells the workflow engine what to do with the activity.

  • Task Activities 50