{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":874,"path":"api-reference/server-api-reference/PlaybookExperienceScopedAPI.md","title":"PlaybookExperience - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# PlaybookExperience- Scoped\n\nThe PlaybookExperience API provides methods for handling playbook executions.\n\nThis API requires the Playbook Experience Core plugin \\(com.glide.playbook\\_experience.config\\) and is provided within the `sn_playbook` namespace.\n\nThis 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](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/process-automation-designer.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## PlaybookExperience - cancelPlaybook\\(String playbookContext, String cancellationReason, String playbookExperienceId, Boolean force\\)\n\nCancel an individual playbook.\n\n<table id=\"table_xxz_j4z_dfc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nplaybookContext\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe \\[sys\\_pd\\_context\\] record that you want to cancel.\n\n</td></tr><tr><td>\n\ncancellationReason\n\n</td><td>\n\nString\n\n</td><td>\n\nThe reason for canceling the playbook execution. This appears in the UI for runtime users as well.\n\n</td></tr><tr><td>\n\nplaybookExperienceId\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Sys\\_id of the playbook experience record in the Playbook Experience \\[sys\\_playbook\\_experience\\] table to use for the cancellation. Use this parameter if you've defined custom activity state mappings. See [Playbook activity state mapping](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/playbook-activity-state-mapping.md).Default: Sys\\_id of the Global Playbook Experience record.\n\n</td></tr><tr><td>\n\nforce\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. If set to true, cancels the underlying flows for activities that are In Progress. The cancellationReason parameter is not used when this parameter is set to true. You can only force cancel activities after the playbook is cancelled and the sys\\_pd\\_context is in a Pending Cancel state.**Note:** The flow engine attempts to cancel all underlying flows without creating issues when a playbook is canceled, but we cannot guarantee that no issues will occur.\n\n</td></tr></tbody>\n</table><table id=\"table_yxz_j4z_dfc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext\n\n</td><td>\n\nThe cancelled playbook execution associated data, such as the reason why it was cancelled.Data type: Array\n\n ```\n\"canceledPlaybookContext\": [\n    {\n      \"can_read\": Boolean,\n      \"canceled_by\": \"String\",\n      \"can_add_activity\": Boolean,\n      \"snapshot_id\": \"string\",\n      \"can_restart\": Boolean,\n      \"can_cancel\": Boolean,\n      \"cancellation_reason\": \"String\",\n      \"errors\": [Array],\n      \"parent_record\": \"String\",\n      \"parent_table\": \"String\",\n      \"playbook_id\": \"String\",\n      \"playbook_table\": \"String\",\n      \"scoped_name\": \"String\",\n      \"variant_id\": \"String\",\n      \"is_archived\": Boolean,\n      \"state\": {Object},\n      \"sys_id\": \"String\",\n      \"title\": \"String\"   \n    }\n]\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.can\\_add\\_activity\n\n</td><td>\n\nFlag that indicates whether a user can add an optional activity to the playbook.Valid values:\n\n-   true: Current user can add an optional activity to the playbook.\n-   false: Current user can’t add an optional activity to the playbook.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.can\\_cancel\n\n</td><td>\n\nFlag that indicates whether a user can cancel a playbook.-   true: The process definition for the deactivated playbook is active.\n-   false: The process definition for the deactivated playbook is inactive.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.can\\_read\n\n</td><td>\n\nFlag that indicates whether the current user can read the playbook execution record. The current user must have read access to the parent record to be able to read the playbook execution record.\n\n Valid values:\n\n-   true: Current user has read access to the playbook execution record.\n-   false: Current user doesn't have read access to the playbook execution record.\n\n Data type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.can\\_restart\n\n</td><td>\n\nFlag that indicates whether a user can restart a playbook, stage, or activity.-   true: Current user can restart the playbook, stage, or activity.\n-   false: Current user can’t restart the playbook, stage, or activity.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.canceled\\_by\n\n</td><td>\n\nThe **User ID** of the user who cancelled the playbook execution.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.cancellation\\_reason\n\n</td><td>\n\nThe cancellation reason input by the user who cancelled the playbook execution.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.errors\n\n</td><td>\n\nList of cancellation errors. Each error is an object in the array.Data type: Array\n\n ```\n\"errors\": [\n    {      \n      \"message\": \"String\",\n      \"type\": \"String\"  \n    }\n]\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.errors.message\n\n</td><td>\n\nThe error message.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.errors.type\n\n</td><td>\n\nThe type of error.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.is\\_archived\n\n</td><td>\n\nFlag that indicates whether playbook context records are archived. Set to true. This value can’t be modified.Possible values:\n\n-   true: Playbook context records are archived.\n-   false: Playbook context records aren’t archived.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.parent\\_record\n\n</td><td>\n\nSys\\_id of the parent record that playbook executions were cancelled for.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.parent\\_table\n\n</td><td>\n\nThe name of the table that the parent record is from.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.playbook\\_id\n\n</td><td>\n\nSys\\_id of the playbook from the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.playbook\\_table\n\n</td><td>\n\nThe name of the table that the playbook is from, generally the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.scoped\\_name\n\n</td><td>\n\nThe scoped name of the playbook from the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table in the format `scope.name`.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.snapshot\\_id\n\n</td><td>\n\nSys\\_id of the snapshot of the playbook execution from the \\[sys\\_pd\\_snapshot\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.state\n\n</td><td>\n\nThe state of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: Object\n\n ```\n\"state\": {    \n   \"displayValue\": \"String\",    \n   \"value\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.state.displayValue\n\n</td><td>\n\nThe display value of the playbook execution state.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.state.value\n\n</td><td>\n\nThe value of the playbook execution state.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.sys\\_id\n\n</td><td>\n\nSys\\_id of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.title\n\n</td><td>\n\nThe label of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.variant\\_id\n\n</td><td>\n\nSys\\_id of the playbook variant execution from the Process Executions \\[sys\\_pd\\_context\\] table.\n\n</td></tr></tbody>\n</table>This example shows how to cancel a single execution of a specific playbook that is running too long.\n\n```\nvar process = new GlideRecord('sys_pd_context');\n\nprocess.get(\"SYS_ID\");\n\nvar cancelPlaybookReturn = sn_playbook.PlaybookExperience.cancelPlaybook(process, \"This playbook ran for too long\");\n\ngs.info(JSON.stringify(cancelPlaybookReturn));\n```\n\nOutput:\n\n```\n{\n \"scoped_name\": \"global.test_user_form\",\n \"canceled_by\": \"maint\",\n \"can_add_activity\": true,\n \"snapshot_id\": \"28ec63425459e250f87766647bf35e7e\",\n \"playbook_table\": \"sys_pd_process_definition\",\n \"can_restart\": false,\n \"can_cancel\": true,\n \"title\": \"Test User Form\",\n \"cancellation_reason\": \"This process ran for too long\",\n \"parent_table\": \"incident\",\n \"can_read\": true,\n \"sys_id\": \"418b1e7ea722435bb4facac50fc9b4f3\",\n \"variant_id\": null,\n \"is_archived\": false,\n \"state\": {\n   \"displayValue\": \"Pending Cancel\",\n   \"value\": \"PENDING_CANCEL\"\n },\n \"parent_record\": \"8cdc23425459e250f87766647bf35ea1\",\n \"playbook_id\": \"d589efca5419e250f87766647bf35e29\",\n \"errors\": []\n}\n```\n\nForce cancel a single execution of a specific playbook.\n\n```\nvar forceCancelPlaybookReturn = sn_playbook.PlaybookExperience.cancelPlaybook(process, \"This playbook did not cancel\", undefined, true);\n\ngs.info(JSON.stringify(forceCancelPlaybookReturn));\n```\n\nOutput:\n\n```\n{\n \"scoped_name\": \"global.test_user_form\",\n \"canceled_by\": \"maint\",\n \"can_add_activity\": true,\n \"snapshot_id\": \"28ec63425459e250f87766647bf35e7e\",\n \"playbook_table\": \"sys_pd_process_definition\",\n \"can_restart\": false,\n \"can_cancel\": true,\n \"title\": \"Test User Form\",\n \"cancellation_reason\": \"This process ran for too long\",\n \"parent_table\": \"incident\",\n \"can_read\": true,\n \"sys_id\": \"418b1e7ea722435bb4facac50fc9b4f3\",\n \"variant_id\": null,\n \"is_archived\": false,\n \"state\": {\n   \"displayValue\": \"Cancelled\",\n   \"value\": \"CANCELLED\"\n },\n \"parent_record\": \"8cdc23425459e250f87766647bf35ea1\",\n \"playbook_id\": \"d589efca5419e250f87766647bf35e29\",\n \"errors\": []\n}\n```\n\n## PlaybookExperience - cancelPlaybooksByParentRecord\\(GlideRecord parentRecord, String cancellationReason, String scopedName, String playbookExperienceId\\)\n\nCancels playbook executions for a given parent record.\n\n<table id=\"table_udh_zjr_ypb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nparentRecord\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe parent record to cancel playbook executions for. The parent record can be any record that has playbook executions, such as an interaction record or an onboarding case record.\n\n</td></tr><tr><td>\n\ncancellationReason\n\n</td><td>\n\nString\n\n</td><td>\n\nThe reason for cancelling the playbook executions.\n\n</td></tr><tr><td>\n\nscopedName\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. The scoped name of the playbook to cancel. 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 cancelled for the given parent record. If not provided, all executions of all playbooks are cancelled for the given parent record.\n\n</td></tr><tr><td>\n\nplaybookExperienceId\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Sys\\_id of the playbook experience record in the Playbook Experience \\[sys\\_playbook\\_experience\\] table to use for the cancellation. Use this parameter if you've defined custom activity state mappings. See[Playbook activity state mapping](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/playbook-activity-state-mapping.md).Default: Sys\\_id of the Global Playbook Experience record.\n\n</td></tr></tbody>\n</table><table id=\"table_vdh_zjr_ypb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nObject containing the cancelled playbook executions and any skipped playbook executions that were unable to be cancelled. ```\n{\n  \"canceledPlaybookContext\": [Array],\n  \"skippedPlaybookContext\": [Array]\n}\n\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext\n\n</td><td>\n\nList of the cancelled playbook executions. Each playbook execution is an object in the array.Data type: Array\n\n ```\n\"canceledPlaybookContext\": [\n    {\n      \"can_read\": Boolean,\n      \"canceled_by\": \"String\",\n      \"cancellation_reason\": \"String\",\n      \"errors\": [Array],\n      \"parent_record\": \"String\",\n      \"parent_table\": \"String\",\n      \"playbook_id\": \"String\",\n      \"playbook_table\": \"String\",\n      \"scoped_name\": \"String\",\n      \"state\": {Object},\n      \"sys_id\": \"String\",\n      \"title\": \"String\"   \n    }\n]\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.can\\_add\\_activity\n\n</td><td>\n\nFlag that indicates whether a user can add an optional activity to the playbook.Valid values:\n\n-   true: Current user can add an optional activity to the playbook.\n-   false: Current user can’t add an optional activity to the playbook.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.can\\_cancel\n\n</td><td>\n\nFlag that indicates whether a user can cancel a playbook.-   true: The process definition for the deactivated playbook is active.\n-   false: The process definition for the deactivated playbook is inactive.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.can\\_read\n\n</td><td>\n\nFlag that indicates whether the current user can read the playbook execution record. The current user must have read access to the parent record to be able to read the playbook execution record.\n\n Valid values:\n\n-   true: Current user has read access to the playbook execution record.\n-   false: Current user doesn't have read access to the playbook execution record.\n\n Data type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.can\\_restart\n\n</td><td>\n\nFlag that indicates whether a user can restart a playbook, stage, or activity.-   true: Current user can restart the playbook, stage, or activity.\n-   false: Current user can’t restart the playbook, stage, or activity.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.canceled\\_by\n\n</td><td>\n\nThe **User ID** of the user who cancelled the playbook execution.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.cancellation\\_reason\n\n</td><td>\n\nThe cancellation reason input by the user who cancelled the playbook execution.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.errors\n\n</td><td>\n\nList of cancellation errors. Each error is an object in the array.Data type: Array\n\n ```\n\"errors\": [\n    {      \n      \"message\": \"String\",\n      \"type\": \"String\"  \n    }\n]\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.errors.message\n\n</td><td>\n\nThe error message.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.errors.type\n\n</td><td>\n\nThe type of error.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.is\\_archived\n\n</td><td>\n\nFlag that indicates whether playbook context records are archived. Set to true. This value can’t be modified.Possible values:\n\n-   true: Playbook context records are archived.\n-   false: Playbook context records aren’t archived.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.parent\\_record\n\n</td><td>\n\nSys\\_id of the parent record that playbook executions were cancelled for.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.parent\\_table\n\n</td><td>\n\nThe name of the table that the parent record is from.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.playbook\\_id\n\n</td><td>\n\nSys\\_id of the playbook from the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.playbook\\_table\n\n</td><td>\n\nThe name of the table that the playbook is from, generally the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.scoped\\_name\n\n</td><td>\n\nThe scoped name of the playbook from the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table in the format `scope.name`.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.snapshot\\_id\n\n</td><td>\n\nSys\\_id of the snapshot of the playbook execution from the \\[sys\\_pd\\_snapshot\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.state\n\n</td><td>\n\nThe state of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: Object\n\n ```\n\"state\": {    \n   \"displayValue\": \"String\",    \n   \"value\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.state.displayValue\n\n</td><td>\n\nThe display value of the playbook execution state.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.state.value\n\n</td><td>\n\nThe value of the playbook execution state.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.sys\\_id\n\n</td><td>\n\nSys\\_id of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.title\n\n</td><td>\n\nThe label of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.skippedPlaybookContext\n\n</td><td>\n\nList of the skipped playbook executions. Each playbook execution is an object in the array. For descriptions of the object properties, see the **canceledPlaybookContext** array. Data type: Array\n\n ```\n\"skippedPlaybookContext\": [\n    {\n      \"can_read\": Boolean,\n      \"canceled_by\": \"String\",\n      \"cancellation_reason\": \"String\",\n      \"errors\": [Array],\n      \"parent_record\": \"String\",\n      \"parent_table\": \"String\",\n      \"playbook_id\": \"String\",\n      \"playbook_table\": \"String\",\n      \"scoped_name\": \"String\",\n      \"state\": {Object},\n      \"sys_id\": \"String\",\n      \"title\": \"String\"   \n    }\n]\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.canceledPlaybookContext.variant\\_id\n\n</td><td>\n\nSys\\_id of the playbook variant execution from the Process Executions \\[sys\\_pd\\_context\\] table.\n\n</td></tr></tbody>\n</table>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.\n\n```\nvar parentRecord = new GlideRecordUtil().getGR(\"interaction\", \"d91742531b343010a26c98a1b24bcbe0\");\n\nvar cancellationReason = \"Cancelling this playbook\";\n\n// demo playbook from Process Automation Experience Demo store app\nvar scopedName = \"sn_pad_demo.playbook_experience_demo\"; \n\n// demo playbook experience from Process Automation Experience Demo store app\nvar playbookExperienceId = \"a56d8d93ff311010cc0853ea793bf1a6\"; \n\t\nvar cancelPlaybookReturn = sn_playbook.PlaybookExperience.cancelPlaybooksByParentRecord(parentRecord, cancellationReason, scopedName, playbookExperienceId);\n\t\n\ngs.info(JSON.stringify(cancelPlaybookReturn, null, 2));\n```\n\nOutput:\n\n```\n{\n  \"canceledPlaybookContext\": [\n    {\n      \"can_read\": true,\n      \"sys_id\": \"d02782533d343010ac50ee17e75d3466\",\n      \"scoped_name\": \"sn_pad_demo.playbook_experience_demo\",\n      \"canceled_by\": \"admin\",\n      \"playbook_table\": \"sys_pd_process_definition\",\n      \"state\": {\n        \"displayValue\": \"Pending Cancel\",\n        \"value\": \"PENDING_CANCEL\"\n      },\n      \"title\": \"Playbook Experience Demo\",\n      \"parent_record\": \"d91742531b343010a26c98a1b24bcbe0\",\n      \"playbook_id\": \"0d35ee1807301010cc08d9630ad3002a\",\n      \"cancellation_reason\": \"Cancelling this playbook\",\n      \"parent_table\": \"interaction\",\n      \"errors\": []\n    }\n  ],\n  \"skippedPlaybookContext\": []\n}\n```\n\n## PlaybookExperience - getPlaybooksForParentRecord\\(GlideRecord parentRecord\\)\n\nGets a list of playbook executions for a given parent record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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.|\n\n<table id=\"table_jpb_gyn_cqb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nArray\n\n</td><td>\n\nList of playbook executions for the parent record. Each playbook execution is an object in the array.```\n[\n    {\n      \"can_read\": Boolean,\n      \"canceled_by\": \"String\",\n      \"cancellation_reason\": \"String\",\n      \"errors\": [Array],\n      \"parent_record\": \"String\",\n      \"parent_table\": \"String\",\n      \"playbook_id\": \"String\",\n      \"playbook_table\": \"String\",\n      \"scoped_name\": \"String\",\n      \"state\": {Object},\n      \"sys_id\": \"String\",\n      \"title\": \"String\"   \n    }\n]\n```\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.can\\_read\n\n</td><td>\n\nFlag that indicates whether the current user can read the playbook execution record. The current user must have read access to the parent record to be able to read the playbook execution record.\n\n Valid values:\n\n-   true: Current user has read access to the playbook execution record.\n-   false: Current user doesn't have read access to the playbook execution record.\n\n Data type: Boolean\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.canceled\\_by\n\n</td><td>\n\nThe **User ID** of the user who cancelled the playbook execution. Empty if the playbook is not cancelled.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.cancellation\\_reason\n\n</td><td>\n\nThe cancellation reason input by the user who cancelled the playbook execution. Empty if the playbook is not cancelled.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.errors\n\n</td><td>\n\nList of errors. Each error is an object in the array.Data type: Array\n\n ```\n\"errors\": [\n    {      \n      \"message\": \"String\",\n      \"type\": \"String\"  \n    }\n]\n```\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.errors.message\n\n</td><td>\n\nThe error message.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.errors.type\n\n</td><td>\n\nThe type of error.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.parent\\_record\n\n</td><td>\n\nSys\\_id of the parent record.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.parent\\_table\n\n</td><td>\n\nThe name of the table that the parent record is from.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.playbook\\_id\n\n</td><td>\n\nSys\\_id of the playbook from the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.playbook\\_table\n\n</td><td>\n\nThe name of the table that the playbook is from, generally the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.scoped\\_name\n\n</td><td>\n\nThe scoped name of the playbook from the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table in the format `scope.name`.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.state\n\n</td><td>\n\nThe state of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: Object\n\n ```\n\"state\": {    \n   \"displayValue\": \"String\",    \n   \"value\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.state.displayValue\n\n</td><td>\n\nThe display value of the playbook execution state.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.state.value\n\n</td><td>\n\nThe value of the playbook execution state.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.sys\\_id\n\n</td><td>\n\nSys\\_id of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: String\n\n</td></tr><tr><td>\n\n&lt;Array&gt;.title\n\n</td><td>\n\nThe label of the playbook execution from the Process Executions \\[sys\\_pd\\_context\\] table.Data type: String\n\n</td></tr></tbody>\n</table>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.\n\n```\nvar parentRecord = new GlideRecordUtil().getGR(\"interaction\", \"148776e5818d7410f87701eb89fdc824\");\nvar playbook = sn_playbook.PlaybookExperience.getPlaybooksForParentRecord(parentRecord);\ngs.info(JSON.stringify(playbook, null, 2));\n\n```\n\nOutput:\n\n```\n[\n  {\n    \"can_read\": true,\n    \"sys_id\": \"bd87bae50b8d7410807a8ffed6d0909e\",\n    \"scoped_name\": \"sn_pad_demo.playbook_experience_demo\",\n    \"canceled_by\": \"\",\n    \"playbook_table\": \"sys_pd_process_definition\",\n    \"state\": {\n      \"displayValue\": \"In Progress\",\n      \"value\": \"IN_PROGRESS\"\n    },\n    \"title\": \"Playbook Experience Demo\",\n    \"parent_record\": \"148776e5818d7410f87701eb89fdc824\",\n    \"playbook_id\": \"0d35ee1807301010cc08d9630ad3002a\",\n    \"cancellation_reason\": \"\",\n    \"parent_table\": \"interaction\",\n    \"errors\": []\n  }\n]\n\n```\n\n## PlaybookExperience - parentRecordContainsPlaybook\\(GlideRecord parentRecord, String scopedName\\)\n\nChecks whether a parent record has playbook executions.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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.|\n|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.|\n\n<table id=\"table_b4v_txn_cqb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the parent record has playbook executions.\n\n Valid values:\n\n-   true: Parent record has playbook executions.\n-   false: Parent record doesn't have playbook executions.\n\n</td></tr></tbody>\n</table>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.\n\n```\nvar parentRecord = new GlideRecordUtil().getGR(\"interaction\", \"148776e5818d7410f87701eb89fdc824\");\n\n// demo playbook from Process Automation Experience Demo store app\nvar scopedName = \"sn_pad_demo.playbook_experience_demo\"; \n\nvar hasPlaybooks = sn_playbook.PlaybookExperience.parentRecordContainsPlaybook(parentRecord, scopedName);\ngs.info(hasPlaybooks);\n```\n\nOutput:\n\n```\ntrue\n```\n\n## PlaybookExperience - restartPlaybook\\(GlideRecord playbookContext, String laneContextId, String activityContextId, String playbookExperienceId\\)\n\nRestarts an execution from the beginning \\(the entire playbook\\) or from a specific stage or activity of a playbook.\n\n**Note:** Only playbooks that are In Progress, Queued, or Pending Cancel state can be restarted.\n\n<table id=\"table_udh_zjr_ypb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nplaybookContext\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe playbook context record for the playbook run or execution that you want to restart.Table: Process Execution \\[sys\\_pd\\_context\\]\n\n</td></tr><tr><td>\n\nlaneContextId\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. The sys\\_id of the stage context record for the stage run or execution that you want to restart from. **laneContextId** and **activityContextId** are mutually exclusive; only one of these values can be specified at a time, while the other should be either an empty string or null.\n\n**Note:** Only complete stages can be restarted.\n\nTable: Lane Executions \\[sys\\_pd\\_lane\\_context\\]\n\n</td></tr><tr><td>\n\nactivityContextId\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. The sys\\_id of the activity context record for the activity run or execution that you want to restart from. **laneContextId** and **activityContextId** are mutually exclusive; only one of these values can be specified at a time, while the other should be either an empty string or null.\n\n**Note:** Only complete activities can be restarted.\n\nTable: Activity Executions \\[sys\\_pd\\_activity\\_context\\]\n\n</td></tr><tr><td>\n\nplaybookExperienceId\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. The sys\\_id of the playbook experience that you want to use for the restarted run. Use this parameter if you have defined custom activity state mappings. See [Playbook activity state mapping](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/playbook-activity-state-mapping.md).Default: Global Playbook Experience\n\nTable: Playbook Experience \\[sys\\_playbook\\_experience\\]\n\n</td></tr></tbody>\n</table><table id=\"table_vdh_zjr_ypb\" class=\"returns\"><thead><tr><th>\n\nProperty\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nObject containing the restarted playbook execution details.```\n{\n \"can_add_activity\": Boolean,\n \"can_cancel\": Boolean,\n \"can_read\": Boolean\n \"can_restart\": Boolean,\n \"canceled_by\": \"String\",\n \"cancellation_reason\": \"String\",\n \"errors\": [Array]\n \"is_archived\": Boolean\n \"parent_record\": \"String\",\n \"parent_table\": \"String\",\n \"playbook_id\": \"String\",\n \"playbook_table\": \"String\",\n \"scoped_name\": \"String\",\n \"state\": {Object},\n \"sys_id\": \"String\",\n \"title\": \"String\",\n}\n```\n\n</td></tr><tr><td>\n\ncan\\_add\\_activity\n\n</td><td>\n\nFlag that indicates whether a user can add an optional activity to the playbook.Valid values:\n\n-   true: Current user can add an optional activity to the playbook.\n-   false: Current user can’t add an optional activity to the playbook.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\ncan\\_cancel\n\n</td><td>\n\nFlag that indicates whether a user can cancel a playbook.-   true: The process definition for the deactivated playbook is active.\n-   false: The process definition for the deactivated playbook is inactive.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\ncan\\_read\n\n</td><td>\n\nFlag that indicates whether the current user can read the playbook execution record. The current user must have read access to the parent record to be able to read the playbook execution record.-   true: Current user has read access to the playbook execution record.\n-   false: Current user doesn't have read access to the playbook execution record.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\ncan\\_restart\n\n</td><td>\n\nFlag that indicates whether a user can restart a playbook, stage, or activity.-   true: Current user can restart the playbook, stage, or activity.\n-   false: Current user can’t restart the playbook, stage, or activity.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\ncanceled\\_by\n\n</td><td>\n\n**User ID** of the user who canceled the playbook execution.Data type: String\n\n</td></tr><tr><td>\n\ncancellation\\_reason\n\n</td><td>\n\nCancellation reason entered by the user who canceled the playbook execution.Data type: String\n\n</td></tr><tr><td>\n\nerrors\n\n</td><td>\n\nList of restart errors. Each error is an object in the array.Data type: Array\n\n```\n\"errors\": [\n {      \n  \"message\": \"String\",\n  \"type\": \"String\"  \n }\n]\n```\n\n</td></tr><tr><td>\n\nis\\_archived\n\n</td><td>\n\nFlag that indicates whether playbook context records are archived.Possible values:\n\n-   true: Playbook context records are archived.\n-   false: Playbook context records aren’t archived.\n\nData type: Boolean\n\n</td></tr><tr><td>\n\nparent\\_record\n\n</td><td>\n\nSys\\_id of the parent record that playbook executions were restarted for.Data type: String\n\n</td></tr><tr><td>\n\nparent\\_table\n\n</td><td>\n\nName of the table that the parent record is from.Data type: String\n\n</td></tr><tr><td>\n\nplaybook\\_id\n\n</td><td>\n\nSys\\_id of the playbook.Data type: String\n\nTable: Process Definitions \\[sys\\_pd\\_process\\_definition\\]\n\n</td></tr><tr><td>\n\nplaybook\\_table\n\n</td><td>\n\nName of the table that the playbook is from, generally the Process Definitions \\[sys\\_pd\\_process\\_definition\\] table.Data type: String\n\n</td></tr><tr><td>\n\nscoped\\_name\n\n</td><td>\n\nOptional. The scoped name of the playbook to restart. 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 restarted for the given parent record. If not provided, all executions of all playbooks are restarted for the given parent record.Data type: String\n\n</td></tr><tr><td>\n\nstate\n\n</td><td>\n\nIndicates whether your request to activate was successful.Data type: Object\n\nPossible values:\n\n-   SUCCESS: The playbook was successfully activated.\n-   FAILURE: The ID for the playbook wasn’t found.\n\n```\n\"state\": [\n    {      \n      \"displayValue\": \"String\",\n      \"value\": \"String\"  \n    }\n]\n```\n\n</td></tr><tr><td>\n\nstate.displayValue\n\n</td><td>\n\nDisplay value of the playbook execution state.Data type: String\n\n</td></tr><tr><td>\n\nstate.value\n\n</td><td>\n\nValue of the playbook execution state.Data type: String\n\n</td></tr><tr><td>\n\nsys\\_id\n\n</td><td>\n\nSys\\_id of the playbook execution.Data type: String\n\nTable: Process Executions \\[sys\\_pd\\_context\\]\n\n</td></tr><tr><td>\n\ntitle\n\n</td><td>\n\nLabel of the playbook execution.Data type: String\n\nTable: Process Executions \\[sys\\_pd\\_context\\]\n\n</td></tr></tbody>\n</table>This example shows how to restart an entire playbook run with the Process Executions \\[sys\\_pd\\_context\\] record ID 98e4fe04591b4caca59583f7b8e30b0a.\n\n```\nvar gr = new GlideRecord('sys_pd_context');\nvar found = gr.get('98e4fe04591b4caca59583f7b8e30b0a'); \nif (found) {\n    var result = sn_playbook.PlaybookExperience.restartPlaybook(gr);\n    gs.info(JSON.stringify(result));\n}\nelse\n    gs.info('invalid pd context');\n```\n\nOutput:\n\n```\n{\n \"scoped_name\": \"global.restart_scriptable_demo\",\n \"canceled_by\": \"\",\n \"can_add_activity\": true,\n \"playbook_table\": \"sys_pd_process_definition\",\n \"can_restart\": true,\n \"can_cancel\": true,\n \"title\": \"Restart scriptable demo\",\n \"cancellation_reason\": \"\",\n \"parent_table\": \"interaction\",\n \"can_read\": true,\n \"sys_id\": \"98e4fe04591b4caca59583f7b8e30b0a\",\n \"is_archived\": false,\n \"state\": {\n   \"displayValue\": \"In Progress\",\n   \"value\": \"IN_PROGRESS\"\n },\n \"parent_record\": \"b88623beb5e10210f877d783f6f83a46\",\n \"playbook_id\": \"12d5a7fab5e10210f877d783f6f83aff\",\n \"errors\": []\n}\n```\n\n## PlaybookExperience - triggerPlaybook\\(String scopedName, GlideRecord parentRecord\\)\n\nInitiates a playbook for a parent record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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`.|\n|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.|\n\n|Type|Description|\n|----|-----------|\n|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.|\n\nThis 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.\n\n```\nvar parentRecord = new GlideRecordUtil().getGR(\"interaction\", \"148776e5818d7410f87701eb89fdc824\");\n\n// demo playbook from Process Automation Experience Demo store app\nvar scopedName = \"sn_pad_demo.playbook_experience_demo\"; \n\nvar playbookExecution = sn_playbook.PlaybookExperience.triggerPlaybook(scopedName, parentRecord);\ngs.info(playbookExecution);\n\n```\n\nOutput:\n\n```\nf059958267cdb410952864f0fed358cc\n```\n\n"}}