The PlaybookExperience API provides methods for handling playbook executions.

This API requires the Playbook Experience Core plugin (com.glide.playbook_experience.config) and is provided within the sn_playbook namespace.

This API requires at least one playbook in the Process Definition [sys_pd_process_definition] table. To use this API, you must have the roles required to view and cancel a running process in Process Automation Designer. For more information, see Process Automation Designer.

PlaybookExperience - cancelPlaybooksByParentRecord(GlideRecord parentRecord, String cancellationReason, String scopedName, String playbookExperienceId)

Cancels playbook executions for a given parent record.

Example

This example shows how to cancel all executions of a specific playbook (in this case, the Playbook Experience Demo) for a given interaction record. To use this method in a UI action or business rule, pass the current object as the parentRecord instead.

var parentRecord = new GlideRecordUtil().getGR("interaction", "d91742531b343010a26c98a1b24bcbe0");

var cancellationReason = "Cancelling this playbook";

// demo playbook from Process Automation Experience Demo store app
var scopedName = "sn_pad_demo.playbook_experience_demo"; 

// demo playbook experience from Process Automation Experience Demo store app
var playbookExperienceId = "a56d8d93ff311010cc0853ea793bf1a6"; 
	
var cancelPlaybookReturn = sn_playbook.PlaybookExperience.cancelPlaybooksByParentRecord(parentRecord, cancellationReason, scopedName, playbookExperienceId);
	

gs.info(JSON.stringify(cancelPlaybookReturn, null, 2));

Output:

{
  "canceledPlaybookContext": [
    {
      "can_read": true,
      "sys_id": "d02782533d343010ac50ee17e75d3466",
      "scoped_name": "sn_pad_demo.playbook_experience_demo",
      "canceled_by": "admin",
      "playbook_table": "sys_pd_process_definition",
      "state": {
        "displayValue": "Pending Cancel",
        "value": "PENDING_CANCEL"
      },
      "title": "Playbook Experience Demo",
      "parent_record": "d91742531b343010a26c98a1b24bcbe0",
      "playbook_id": "0d35ee1807301010cc08d9630ad3002a",
      "cancellation_reason": "Cancelling this playbook",
      "parent_table": "interaction",
      "errors": []
    }
  ],
  "skippedPlaybookContext": []
}

PlaybookExperience - getPlaybooksForParentRecord(GlideRecord parentRecord)

Gets a list of playbook executions for a given parent record.

Table 3. Parameters
Name Type Description
parentRecord GlideRecord The parent record to get playbook executions for. The parent record can be any record that can have playbook executions, such as an interaction record or an onboarding case record.

Example

This example shows how to get playbook executions for a given interaction record. To use this method in a UI action or business rule, pass the current object as the parentRecord instead.

var parentRecord = new GlideRecordUtil().getGR("interaction", "148776e5818d7410f87701eb89fdc824");
var playbook = sn_playbook.PlaybookExperience.getPlaybooksForParentRecord(parentRecord);
gs.info(JSON.stringify(playbook, null, 2));

Output:

[
  {
    "can_read": true,
    "sys_id": "bd87bae50b8d7410807a8ffed6d0909e",
    "scoped_name": "sn_pad_demo.playbook_experience_demo",
    "canceled_by": "",
    "playbook_table": "sys_pd_process_definition",
    "state": {
      "displayValue": "In Progress",
      "value": "IN_PROGRESS"
    },
    "title": "Playbook Experience Demo",
    "parent_record": "148776e5818d7410f87701eb89fdc824",
    "playbook_id": "0d35ee1807301010cc08d9630ad3002a",
    "cancellation_reason": "",
    "parent_table": "interaction",
    "errors": []
  }
]

PlaybookExperience - parentRecordContainsPlaybook(GlideRecord parentRecord, String scopedName)

Checks whether a parent record has playbook executions.

Table 5. Parameters
Name Type Description
parentRecord GlideRecord The parent record to check for playbook executions. The parent record can be any record that can have playbook executions, such as an interaction record or an onboarding case record.
scopedName String Optional. The scoped name of the playbook to check for. The scoped name is from the Process Definition [sys_pd_process_definition] table in the format scope.name. If provided, only executions of this playbook are checked for. If not provided, executions of all playbooks are checked for.
Table 6. Returns
Type Description
Boolean

Flag that indicates whether the parent record has playbook executions.

Valid values:
  • true: Parent record has playbook executions.
  • false: Parent record doesn't have playbook executions.

Example

This example shows how to check if a given interaction record has executions of a specific playbook (in this case, the Playbook Experience Demo). To use this method in a UI action or business rule, pass the current object as the parentRecord instead.

var parentRecord = new GlideRecordUtil().getGR("interaction", "148776e5818d7410f87701eb89fdc824");

// demo playbook from Process Automation Experience Demo store app
var scopedName = "sn_pad_demo.playbook_experience_demo"; 

var hasPlaybooks = sn_playbook.PlaybookExperience.parentRecordContainsPlaybook(parentRecord, scopedName);
gs.info(hasPlaybooks);

Output:

true

PlaybookExperience - restartPlaybook(String playbookContextId, String laneContextId, String activityContextId, String playbookExperienceId)

Restarts an execution from the beginning (the entire playbook) or from a specific stage or activity of a playbook.

Note: Only playbooks that are In Progress, Queued, or Pending Cancel state can be restarted.

Example

This example shows how to restart an entire playbook run with the Process Executions [sys_pd_context] record ID 98e4fe04591b4caca59583f7b8e30b0a.

var gr = new GlideRecord('sys_pd_context');
var found = gr.get('98e4fe04591b4caca59583f7b8e30b0a'); 
if (found) {
    var result = sn_playbook.PlaybookExperience.restartPlaybook(gr);
    gs.info(JSON.stringify(result));
}
else
    gs.info('invalid pd context');

Output:

{
 "scoped_name": "global.restart_scriptable_demo",
 "canceled_by": "",
 "can_add_activity": true,
 "playbook_table": "sys_pd_process_definition",
 "can_restart": true,
 "can_cancel": true,
 "title": "Restart scriptable demo",
 "cancellation_reason": "",
 "parent_table": "interaction",
 "can_read": true,
 "sys_id": "98e4fe04591b4caca59583f7b8e30b0a",
 "is_archived": false,
 "state": {
   "displayValue": "In Progress",
   "value": "IN_PROGRESS"
 },
 "parent_record": "b88623beb5e10210f877d783f6f83a46",
 "playbook_id": "12d5a7fab5e10210f877d783f6f83aff",
 "errors": []
}

PlaybookExperience - triggerPlaybook(String scopedName, GlideRecord parentRecord)

Initiates a playbook for a parent record.

Table 9. Parameters
Name Type Description
scopedName String The scoped name of the playbook to initiate. The scoped name is from the Process Definition [sys_pd_process_definition] table in the format scope.name.
parentRecord GlideRecord The parent record to initiate a playbook for. The parent record can be any record that can have playbook executions, such as an interaction record or an onboarding case record.
Table 10. Returns
Type Description
String Sys_id of the playbook execution from the Process Executions [sys_pd_context] table that was created for the parent record. Null if a playbook execution wasn't successfully created.

Example

This example shows how to initiate a playbook for a given interaction record. To use this method in a UI action or business rule, pass the current object as the parentRecord instead.

var parentRecord = new GlideRecordUtil().getGR("interaction", "148776e5818d7410f87701eb89fdc824");

// demo playbook from Process Automation Experience Demo store app
var scopedName = "sn_pad_demo.playbook_experience_demo"; 

var playbookExecution = sn_playbook.PlaybookExperience.triggerPlaybook(scopedName, parentRecord);
gs.info(playbookExecution);

Output:

f059958267cdb410952864f0fed358cc