{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":4041,"path":"build-workflows/workflow-studio/create-custom-action-throw-error.md","title":"Create a custom action to throw an error","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create a custom action to throw an error\n\nCreate an action that intentionally throws an error to test flow error handling.\n\n## Before you begin\n\nRole required: flow\\_designer, action\\_designer, or admin\n\n## About this task\n\nThis custom action throws an error when the action input value is set to 1. Any other input value allows the action to run without throwing an error. You can add this custom action to a flow to test flow error handling.\n\n## Procedure\n\n1.  Navigate to **All** &gt; **Process Automation** &gt; **Flow Designer**.\n\n    The system displays the Workflow Studio landing page.\n\n2.  Select **New** &gt; **Action**\n\n    The system displays the Action Properties dialog.\n\n3.  Enter these sample values.\n\n    |Field|Value|\n    |-----|-----|\n    |Name|Throw an error|\n    |Application|Global|\n    |Accessible From|All application scopes|\n\n4.  Select **Build Action**.\n\n    The system displays the Workflow Studio interface.\n\n5.  From the Action Outline, select **Inputs** &gt; **Create Input**\n\n    The system displays a new action input.\n\n6.  Configure the action input with these values.\n\n    |Field|Value|\n    |-----|-----|\n    |Label|Error Code|\n    |Type|Integer|\n    |Mandatory|True|\n\n7.  From the Action Outline, select **Add a new step**.\n\n    The system displays a list of available steps.\n\n8.  Select **Script step**.\n\n9.  From the **Input Variables** section, select **Create Variable**.\n\n10. Configure the variable with these values.\n\n<table id=\"table_cvp_l5p_lhb\"><thead><tr><th>\n\nField\n\n</th><th>\n\nValue\n\n</th></tr></thead><tbody><tr><td>\n\nName\n\n</td><td>\n\ncode\n\n **Note:** Make sure that this value is lower case so that it matches the script call reference in the next step.\n\n</td></tr><tr><td>\n\nValue\n\n</td><td>\n\nSelect the data pill \\[action-&gt;Error Code\\]\n\n</td></tr></tbody>\n</table>11. In **Script**, enter this JavaScript code.\n\n    ```\n    (function execute(inputs, outputs) {\n      if (inputs.code == 1) {\n          throw 'My custom error message'\n          }\n    })(inputs, outputs);\n    ```\n\n12. Select **Save**.\n\n    \\[Omitted image \"create-action-throw-error.png\"\\] Alt text: Action outline and configuration of the sample action Throw an error.\n\n13. Select **Test**.\n\n    The system displays the Test Action dialog.\n\n14. Enter the following test value:\n\n    |Input|Value|\n    |-----|-----|\n    |Error Code|1|\n\n15. Select **Run Test**.\n\n    The system runs the action with the test values provided.\n\n16. Select **Your test has finished running. View the action execution details.**\n\n    The system displays the action execution details.\n\n17. Verify that the action ran the Script step and threw your custom error message.\n\n    The **Action Status** object should list an error on line 3 and display the text of your custom error message.\n\n    \\[Omitted image \"test-action-throw-error.png\"\\] Alt text: Action execution details for a test run of Throw an error.\n\n18. Close the action execution details.\n\n19. Select **Cancel** to stop testing the action.\n\n20. Select **Publish** to make your custom action available to your flows.\n\n\n## Result\n\nYou have a custom action that throws an error when you set the action input **Error Code** to 1.\n\n## What to do next\n\nAdd this action to a flow to test the contents of the Error Handler section.\n\n**Parent Topic:**[Flow error handler](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/flow-error-handler.md)\n\n"}}