Skip to main content

08 - Create the 'ServiceNow Create Incident' tool

In this module we will create a stateful workflow to create a ServiceNow incident. Our Agent Loop will leverage this workflow as a tool when processing user requests.

Create Stateful Workflow

  1. Create a new workflow:

    • Navigate to the Workflows -> Workflows section of your Logic app

    • Click + Add -> Add

      Add Workflow

  2. Create a new stateful workflow with:

    • Workflow name: tool-ServiceNow-CreateIncident
    • Select the radio button for the Stateful workflow type
    • Click Create

    Create Stateful Workflow

  3. Open the workflow visual editor by clicking on the tool-ServiceNow-CreateIncident link

    Open Workflow

Configure Workflow

  1. Configure the workflow trigger to accept an HTTP Request

    • Click on Add Trigger

    • Select the Request action located in the Built-in tools group

      Add Trigger - Request Action

    • Select the When a HTTP request is received

      Select Action When a HTTP Request is Received

  2. Configure the When a HTTP request is received action:

    • Request Body JSON Schema
      {
      "type": "object",
      "properties": {
      "AssignmentGroup": {
      "type": "string"
      },
      "Description": {
      "type": "string"
      },
      "FailureDateTime": {
      "type": "string"
      },
      "ResolutionSteps": {
      "type": "string"
      },
      "Severity": {
      "type": "string"
      }
      }
      }
  3. Look up the internal identifier for the Assignment Group in ServiceNow. The Assignment Group is the group of the team that will be responsible for resolving the particular incident. By assigning, this value during ticket creation, we can ensure that it is assigned appropriately.

    • Add a new action. Click + Add an action

      Add an action

    • Select the ServiceNow - List Records action

      Select Action ServiceNow List Records

  4. Configure the ServiceNow - List Records activity.

    • Configure the Connection:

      • Connection Name: connServiceNowDev
      • Authentication Type: Use Oauth2
      • Instance Name: [obtained from Module 2]
        • example: devXXXXXX
        • can also be found in the URL of your developer instance https://[instance name].service-now.com
    • ClientId: [obtained from Module 2 - ]

      • example: 924168e8304a2210cc58c3f34c9b62f3
      • Click Sign in

      Configure ServiceNow Connection

    • NOTE you may receive the following error.

      ServiceNow Connection Error - Invalid Redirect URI

      If you receive this error you will need to:

      ServiceNow Connection Error - Invalid Redirect URI

    • Close the browser popup window

    • Click the Sign In button again

      Note please check for errors in the upper right hand corner of your browser. Some browsers may block popups.

      ServiceNow Connection - Sign In

  5. Click Allow granting Logic Apps permission to connect to your ServiceNow instance

    Service Now Grant Permissions

  6. Configure the List Records Activity as follows

    • Record Type: Group
    • Advanced Parameters (click Show all)
    • Query: name=@{triggerBody()?['AssignmentGroup']}

    ServiceNow List Activity Configuration

  7. Add a new action

  8. Select the ServiceNow - Create Record action

    Service Now - Create Record Action

  9. Configure the Create Record action as follows:

    • Rename action to: Create Record-Incident
    • Record Type: Incident
    • Advanced Parameters:
      • you can show selected advanced parameters by clicking on the dropdown and select each parameter individually
      • Short Description:
        The following error occurred and needs to be investigated: @{triggerBody()?['Description']} 
      • Assignment Group:
        @{first(body('List_Records-AssignmentGroups')?['result'])['sys_id']}
      • Description:
        The following workflow failed and needs to be investigated:

        Error Message: @{triggerBody()?['Description']}

        Additional Information: @{triggerBody()?['FailureDateTime']}
        Resolution Steps (from Operation Manual):
        @{triggerBody()?['ResolutionSteps']}
      • Severity:
        @{triggerBody()?['Severity']}
      Configure ServiceNow Create Record
  10. Add the Request (Built-in) -> Response action

    Add Action Response

  11. Configure the Response action as follows:

    • Status Code: 200
    • Body:
      {
      "TicketNumber": "@{body('Create_Record-Incident')?['result']?['number']}"
      }
    • Response Body JSON Schema
      {
      "type": "object",
      "properties": {
      "TicketNumber": {
      "type": "string"
      }
      }
      }

    Configure Action Response

  12. Click Save to save the changes made to the workflow

    Save Workflow

    You should see a notification once the workflow is saved.

    Save Workflow Confirmation