{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":892,"path":"api-reference/server-api-reference/RemedialActionScopedAPI.md","title":"RemedialActionEngine - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# RemedialActionEngine- Scoped\n\nThe RemedialActionEngine API provides methods for working with remedial actions.\n\nThis API is part of the Remedial Actions Framework and can be used to perform the following actions:\n\n-   Kick start a remedial action.\n-   Trigger the execution of a remedial action.\n-   Check the authorization of logged in user to execute the remedial action.\n-   Check the applicability of the remedial action against the target record.\n-   Get the current execution status and output payload of the targeted action.\n\nThis API requires the Remedial Actions Framework \\(com.snc.sn\\_reacf\\) store application and is provided within the `sn_reacf` namespace.\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## RemedialActionEngine - beginRemediation \\(String remedialAction, String parentTable, String parentRecord, Object actionParams, String targetRecord, String originRecord\\)\n\nStarts any remedial action from the parent record against a target record. This method creates a new remedial action execution record in a 'Ready' state.\n\n**Note:** When defining request parameters, remember that:\n\n-   If the parameter type is an object or array, define each property and its type.\n-   If the parameter type is GlideRecord, provide the associated table in your request.\n\n<table id=\"table_dcp_cgs_gxb\" 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\nremedialAction\n\n</td><td>\n\nString or GlideRecord\n\n</td><td>\n\nSys\\_id or internal\\_name or GlideRecord of the femedial action \\[sn\\_reacf\\_remedial\\_action\\] table.\n\n</td></tr><tr><td>\n\nparentTable\n\n</td><td>\n\nString\n\n</td><td>\n\nTable name of the parent record.\n\n</td></tr><tr><td>\n\nparentRecord\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the parent record.\n\n</td></tr><tr><td>\n\nactionParams\n\n</td><td>\n\nObject\n\n</td><td>\n\nOptional. Map of remedial action parameter names and values.\n\n ```\n{\n    “<parameter name>”: <parameter value>\n}\n```\n\n **Note:** Parameter value should be of type defined in remedial action Parameter \\[sn\\_reacf\\_remedial\\_action\\_parameter\\] table.\n\n</td></tr><tr><td>\n\ntargetRecord\n\n</td><td>\n\nString or GlideRecord\n\n</td><td>\n\nOptional. Sys\\_id or GlideRecord of the configured Target table.\n\n</td></tr><tr><td>\n\noriginRecord\n\n</td><td>\n\nString or GlideRecord\n\n</td><td>\n\nOptional. Sys\\_id or GlideRecord of the Remedial Action Origin \\[sn\\_reacf\\_remedial\\_action\\_origin\\] table.\n\n</td></tr></tbody>\n</table><table id=\"table_ecp_cgs_gxb\" 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\n```\n{\n    \"statusCode\": \"String\",\n    \"actionExecutionRequestId\": \"String\",\n    \"parentRecord\": \"String\",\n    \"parentTable\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.statusCode\n\n</td><td>\n\nStatus code of the remedial action execution request i.e. successful, duplicate\\_request or failed\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.actionExecutionRequestId\n\n</td><td>\n\nSys\\_id of the new Rremedial action execution record or duplicate concurrent Remedial Action Execution record\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.parentRecord\n\n</td><td>\n\nSys\\_id of the Parent record of the duplicate concurrent remedial action execution record.\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.parentTable\n\n</td><td>\n\nTable name of the Parent record of the duplicate concurrent remedial action execution record.\n\n</td></tr></tbody>\n</table>The following example shows how to start any remedial action. Here, the remedial action uses a CI Action internally to kill a process on a CI.\n\n```\nvar remedialAction = \"9ef9924c436521101a24ff53e9b8f2d2\" //sys_id of the Action\nvar parentTable = \"incident\"; //table name of the Parent record\nvar parentRecord = \"62733787871e25105763ec6d0ebb3579\" //sys_id of the Parent record\nvar actionParams = {\n    process_id: \"322113\"\n}\nvar targetRecord = \"af57a3418775e5105763ec6d0ebb356d\"; //sys_id of the Target record\nvar originRecord = \"26e78022c3d525104f1a722e3f40dd99\"; //sys_id of the Origin record\n\nvar remedialActionEngine = new sn_reacf.RemedialActionEngine();\nvar response = remedialActionEngine.beginRemediation(remedialAction, parentTable, parentRecord, actionParams, targetRecord, originRecord);\n \ngs.info(JSON.stringify(response));\n\n```\n\nOutput object:\n\n```\nCase 1 :successful : \n{\n  ‘statusCode’: ‘successful’,\n  ‘actionExecutionRequestId: ‘979b6060a5954300964fa3aa92874155’\n\n}\n\nCase 2 :Duplicate : \n{\n  ‘statusCode’: ‘duplicate_request,\n  ‘actionExecutionRequestId’: ‘552c48888c033300964f4932b03eb092’,\n  ‘parentRecord’ : ‘1a14620f973be110539e35d11153afc8’,\n  ‘parentTable’: ‘incident’\n\n}\n\nCase 3 : Failed \n{\n  ‘statusCode’: ‘failed,\n}\n\n```\n\n## RemedialActionEngine - canCancel\\(String remedialActionExecution\\)\n\nThis method is used to check if the current user can or cannot cancel the given remedial action execution.\n\n**Note:** When defining request parameters, remember that:\n\n-   If the parameter type is an object or array, define each property and its type.\n-   If the parameter type is GlideRecord, provide the associated table in your request.\n\n|Name|Type|Description|\n|----|----|-----------|\n|remedialActionExecution|String or GlideRecord|Sys\\_id or GlideRecord of the Remedial Action Execution \\[sn\\_reacf\\_remedial\\_action\\_execution\\] table.|\n\n<table id=\"table_mkw_xrd_3yb\" 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 remedial action execution request can or cannot be canceled.\n\n Valid values:\n\n-   true: The specified remedial action execution request can be canceled.\n-   false: The specified remedial action execution request cannot be canceled.\n\n</td></tr></tbody>\n</table>The following example shows how to validate whether the current user can cancel any remedial action execution in its current state.\n\n```\nvar remedialActionExecutionId = \"9ef9924c436521101a24ff53e9b8f2d2\" //sys_id of sn_reacf_remedia_action_execution record\n\nvar remedialActionEngine = new sn_reacf.RemedialActionEngine();\nvar canCancel = remedialActionEngine.canCancel(remedialActionExecutionId)\n\ngs.info(\"canCancel: \" + canCancel);\n\n```\n\nOutput:\n\n```\ncanCancel: true\n```\n\n## RemedialActionEngine - cancelExecution\\(String remedialActionExecution\\)\n\nCancels a remedial action execution request, then updates the execution record to the state ‘cancelled’ and returns true upon success.\n\n**Note:** When defining request parameters, remember that:\n\n-   If the parameter type is an object or array, define each property and its type.\n-   If the parameter type is GlideRecord, provide the associated table in your request.\n\n|Name|Type|Description|\n|----|----|-----------|\n|remedialActionExecution|String or GlideRecord|Sys\\_id or GlideRecord of the Remedial Action Execution \\[sn\\_reacf\\_remedial\\_action\\_execution\\] table.|\n\n<table id=\"table_mkw_xrd_3yb\" 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 remedial action execution request can or cannot be canceled.\n\n Valid values:\n\n-   true: The specified remedial action execution request is canceled successfully. A status of true updates the execution record to the state ‘cancelled'.\n-   false: The specified remedial action execution request is not canceled successfully.\n\n</td></tr></tbody>\n</table>The following example shows how to cancel any remedial action execution from its current state.\n\n```\nvar remedialActionExecutionId = \"9ef9924c436521101a24ff53e9b8f2d2\" //sys_id of sn_reacf_remedia_action_execution record\n\nvar remedialActionEngine = new sn_reacf.RemedialActionEngine();\nvar cancelExecution = remedialActionEngine.cancelExecution(remedialActionExecutionId)\n\ngs.info(‘cancelExecution: ’ + cancelExecution);\n```\n\nOutput:\n\n```\ncancelExecution : true\n```\n\n## RemedialActionEngine - executeRemedialAction \\(String remedialActionExecution\\)\n\nTriggers any remedial action execution that was started and is currently in Ready state. This method starts the targeted Action \\(e.g. CI Action\\) and moves the remedial action execution state to 'In Progress'.\n\n|Name|Type|Description|\n|----|----|-----------|\n|remedialActionExecution|String or GlideRecord|Sys\\_id or GlideRecord of the Remedial Action Execution \\[sn\\_reacf\\_remedial\\_action\\_execution\\] table.|\n\n<table id=\"table_itl_mfs_gxb\" 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 contains the action\\_execution\\_table and action\\_execution\\_id of the remedial action execution.\n\n ```\n{\n   “action_execution_table”: “String”,\n   “action_execution_id”: “Sys_id”\n}\n\n```\n\n</td></tr></tbody>\n</table>The following example shows how to execute any remedial action.\n\n```\nvar remedialActionExecution = \"8ed58be387d2a5100295ebd73cbb35a3\"; //Sys_id of the Remedial Action Execution record \n \nvar remedialActionEngine = new sn_reacf.RemedialActionEngine(); \nvar response = remedialActionEngine.executeRemedialAction(remedialActionExecution); \ngs.info(\"Response: \" + JSON.stringify(response, null, 2));\n```\n\nOutput:\n\n```\n{ \n  \"action_execution_table\": \"sn_cimaf_action_request\", \n  \"action_execution_id\": \"2d7843a787d2a5100295ebd73cbb35d4\" \n}\n```\n\n## RemedialActionEngine - getRemedialActionOutput \\(String remedialActionExecution\\)\n\nGets the current execution status and output payload of the targeted Action.\n\n|Name|Type|Description|\n|----|----|-----------|\n|remedialActionExecution|String or GlideRecord|Sys\\_id or GlideRecord of the Remedial Action Execution \\[sn\\_reacf\\_remedial\\_action\\_execution\\] table.|\n\n<table id=\"table_stg_32s_gxb\" 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 contains the status object having value and display value of the target Action status, and payload array having the target Action outputs executed as part of the Remedial Action execution.\n\n Data type: String\n\n ```\n{\n  \"status\": {\n    \"value\": \"completed\",\n    \"displayValue\": \"Completed\"\n  },\n  \"payload\": [\n    \"{\\\"output\\\":\\\"SUCCESS: The process with PID 19604 has been terminated.\\\\r\\\\n\\\",\\\"cmd\\\":\\\"taskkill /pid 19604 /f\\\"}\"\n  ]\n}\n```\n\n</td></tr></tbody>\n</table>The following example shows how to get current execution status and output payload of the targeted Action.\n\n```\nvar remedialActionExecution = \"8ed58be387d2a5100295ebd73cbb35a3\"; //sys_id of the Remedial Action Execution record\n\nvar remedialActionEngine = new sn_reacf.RemedialActionEngine();\nvar response = remedialActionEngine.getRemedialActionOutput(remedialActionExecution);\n\ngs.info(\"Response: \" + JSON.stringify(response, null, 2));\n\n```\n\nOutput:\n\n```\n{\n  \"status\": {\n    \"value\": \"completed\",\n    \"displayValue\": \"Completed\"\n  },\n  \"payload\": [\n    \"{\\\"output\\\":\\\"SUCCESS: The process with PID 19604 has been terminated.\\\\r\\\\n\\\",\\\"cmd\\\":\\\"taskkill /pid 19604 /f\\\"}\"\n  ]\n}\n```\n\n## RemedialActionEngine - isApplicable \\(String remedialAction, String targetRecord\\)\n\nChecks the applicability of any remedial action against a target record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|remedialAction|String or GlideRecord|Sys\\_id or internal\\_name or GlideRecord of the remedial action \\[sn\\_reacf\\_remedial\\_action\\] table.|\n|targetRecord|String or GlideRecord|Sys\\_id or GlideRecord of the configured Target table.|\n\n<table id=\"table_n4x_wcs_gxb\" 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 the target record's applicability for the remedial action.\n\n-   true: the Remedial Action is applicable to the specified target record.\n-   false: the Remedial Action is not applicable to the specified target record.\n\n</td></tr></tbody>\n</table>The following example shows how to check applicability of any remedial action against a target record.\n\n```\nvar remedialAction = \"9ef9924c436521101a24ff53e9b8f2d2\"; //Sys_id of the Remedial Action Execution record \nvar targetRecord = \"df3799a387a921100295ebd73cbb35c4\"; //Sys_id of the Target Record \n \nvar remedialActionEngine = new sn_reacf.RemedialActionEngine(); \nvar isApplicable = remedialActionEngine.isApplicable(remedialAction, targetRecord); \ngs.info(\"Is applicable: \" + isApplicable);\n```\n\nOutput:\n\n```\nIs applicable: true\n```\n\n## RemedialActionEngine - isAuthorized\\(String remedialAction\\)\n\nChecks if the user is authorized to execute the remedial action.\n\n|Name|Type|Description|\n|----|----|-----------|\n|remedialAction|String or GlideRecord|Sys\\_id or internal\\_name or GlideRecord of the Remedial Action \\[sn\\_reacf\\_remedial\\_action\\] table.|\n\n<table id=\"table_xpy_jzr_gxb\" 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 the resulting success status of the user's authorization.\n\n -   true: The user's authorization is successful.\n-   false: The user's authorization is unsuccessful.\n\n</td></tr></tbody>\n</table>The following example shows how to check authorization to execute any remedial action.\n\n```\nvar actionSysId = \"e62f550843e121101a24ff53e9b8f23b\"; //Sys_id of the Action \n \nvar remedialActionEngine = new sn_reacf.RemedialActionEngine(); \nvar isAuthorized = remedialActionEngine.isAuthorized(actionSysId); \ngs.info(\"Is user authorized: \" + isAuthorized);\n```\n\nOutput:\n\n```\nIs user authorized: true\n```\n\n"}}