{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":39214,"path":"platform-administration/r_InboundEmailActionExamples.md","title":"Inbound email action examples","bundle":null,"doc_type":null,"release":"australia","body":"\n# Inbound email action examples\n\nVarious examples of inbound email actions are available to help you build your own inbound email actions. These examples show how to set up inbound email actions to handle email replies, create \\(log\\) a problem record, request a change, and update an incident.\n\n**Parent Topic:**[References for Inbound email](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/platform-administration/references-inbound-email.md)\n\n## Inbound email action example: handling email replies\n\nThis example shows you how to set up inbound email actions to handle replies that users send back to the instance.\n\n### Before you begin\n\nRole required: admin\n\n### About this task\n\nThe inbound email action parses the email and responds using a script. By default, an email received by the instance creates a new incident, and the body of the email is added to the **Additional Comments** text box. More refined Inbound Email Actions can create incident tickets with more data, thus saving the incident management team valuable time.\n\nNormally, when a user responds to an email sent by the instance, the inbound email action matches the watermark to an existing incident, and updates the incident rather than creating a new record. However, if the watermark is missing, this inbound email action attempts to match a reply to the original incident.\n\nThis inbound email action is replicated in Workflow Studio as the sample flow **Inbound Email Flow Example: handling email replies**. To view the sample flow, navigate to **Flow Designer** &gt; **Designer**.\n\n### Procedure\n\n1.  Navigate to **System Policy** &gt; **Inbound Actions** and click **New**.\n\n2.  Populate the form as follows:\n\n    |Field|Value|\n    |-----|-----|\n    |Name|Update Incident|\n    |Type|Reply|\n    |Target table|Incident \\[incident\\]|\n\n3.  In **Script**, enter this code.\n\n    ```\n    gs.include('validators');\n     \n    //Note: current.caller_id and current.opened_by are already set to the first UserID that matches the From: email address\n     \n    if (current.getTableName() == \"incident\") {\n      current.comments = \"reply from: \" + email.origemail + \"\\n\\n\" + email.body_text;\n     \n      if (email.body.assign != undefined)\n        current.assigned_to = email.body.assign;\n     \n      if (email.body.priority != undefined && isNumeric(email.body.priority))\n        current.priority = email.body.priority;\n     \n      if (email.body.category != undefined)\n        current.category = email.body.category;\n     \n      if (email.body.short_description != undefined)\n        current.short_description = email.body.short_description;\n     \n      current.update();\n    }\n    ```\n\n\n## Inbound email action example: logging a problem\n\nThis example shows you how to set up inbound email actions to a create a problem record.\n\n### Before you begin\n\nRole required: admin\n\n### About this task\n\nInbound email actions allow users to log or update incidents on an instance via email. The inbound email action parses the email and responds using a script.\n\nThis inbound email action is replicated in Workflow Studio as the sample flow **Inbound Email Flow Example: logging a problem**. To view the sample flow, navigate to **Flow Designer** &gt; **Designer**.\n\n### Procedure\n\n1.  Navigate to **System Policy** &gt; **Inbound Actions** and click **New**.\n\n2.  Populate the form as follows:\n\n<table id=\"simpletable_iry_cjf_hq\"><thead><tr><th>\n\nField\n\n</th><th>\n\nEntry\n\n</th></tr></thead><tbody><tr><td>\n\nName\n\n</td><td>\n\nLog Problem\n\n</td></tr><tr><td>\n\nType\n\n</td><td>\n\nNew\n\n</td></tr><tr><td>\n\nActive\n\n</td><td>\n\nTrue\n\n</td></tr><tr><td>\n\nTarget Table\n\n</td><td>\n\nProblem \\[problem\\]\n\n</td></tr><tr><td>\n\nCondition\n\n</td><td>\n\n```\nemail.subject.indexOf(\"Problem: \") == 0\n```\n\n</td></tr><tr><td>\n\nScript\n\n</td><td>\n\n```\ncurrent.description = email.body_text;\n  current.short_description = email.subject.toString().substring(9);\n \n  current.assignment_group.setDisplayValue(\"Development\");\n \n  if (email.body.assign != undefined)\n    current.assigned_to = email.body.assign;\n \n  current.insert();\n```\n\n</td></tr></tbody>\n</table>\n## Inbound email action example: requesting a change\n\nThis example shows you how to set up inbound email actions to create a change request record.\n\n### Before you begin\n\nRole required: admin\n\n### About this task\n\nInbound Email Actions allow users to log or update incidents on an instance via email. The inbound email action parses the email and responds using a script.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **System Policy** &gt; **Inbound Actions** and click **New**.\n\n2.  Populate the form as follows:\n\n<table id=\"simpletable_iry_cjf_hq\"><thead><tr><th>\n\nField\n\n</th><th>\n\nEntry\n\n</th></tr></thead><tbody><tr><td>\n\nName\n\n</td><td>\n\nRequest Change\n\n</td></tr><tr><td>\n\nType\n\n</td><td>\n\nNew\n\n</td></tr><tr><td>\n\nActive\n\n</td><td>\n\nTrue\n\n</td></tr><tr><td>\n\nTarget Table\n\n</td><td>\n\nChange Request \\[change\\_request\\]\n\n</td></tr><tr><td>\n\nCondition\n\n</td><td>\n\n```\nemail.subject.indexOf(\"Change Request: \") == 0\n```\n\n</td></tr><tr><td>\n\nScript\n\n</td><td>\n\n```\ncurrent.comments = email.body_text;\n  current.short_description = email.subject;\n \n  current.notify = 2;\n \n  if (email.body_text.assign != undefined)\n    current.assigned_to = email.body_text.assign;\n \n  if (email.body_text.priority != undefined)\n    current.priority = email.body_text.priority;\n \n  if (email.body_text.category != undefined)\n    current.category = email.body_text.category;\n \n  current.insert();\n```\n\n</td></tr></tbody>\n</table>\n## Values automatically set from incoming email\n\nThe default inbound action for the Incident table automatically sets the following field values when it receives an incoming email.\n\n|Field value set|Value used from incoming email|\n|---------------|------------------------------|\n|`current.caller_id`|User ID of the first user whose email address matches the `email.from` variable.|\n|`current.opened_by`|User ID of the first user whose email address matches the `email.from` variable.|\n\nIf multiple users have the same email address, the instance first searches for an active user with the email address. Use unique email addresses for each user record whenever possible. If not, having only one active user with the shared email address guarantees that the instance always matches incoming email from this address to the active user.\n\n"}}