Skip to main content

Check out Port for yourselfย 

Delete a ServiceNow incident

Overviewโ€‹

This guide demonstrates how to implement a self-service action in Port that deletes ServiceNow incidents directly from Port using synced webhooks. By combining synced webhooks with Port's automation, you can keep your software catalog clean and synchronized with your ServiceNow environment.

Prerequisitesโ€‹

Set up data source mappingโ€‹

By default, the identifier of the incident kind is mapped to the incident number (.number). However, deleting records in ServiceNow via API requires the system's internal ID (.sys_id). To fix this:

  1. Go to the Data Sources page of your portal.

  2. Select the ServiceNow integration.

  3. Add the following YAML block into the editor to update the incident data:

    Updated ServiceNow integration configuration (Click to expand)
    resources:
    - kind: incident
    selector:
    query: 'true'
    apiQueryParams:
    sysparmDisplayValue: 'true'
    sysparmExcludeReferenceLink: 'false'
    port:
    entity:
    mappings:
    identifier: .sys_id
    title: .short_description
    blueprint: '"servicenowIncident"'
    properties:
    category: .category
    reopenCount: .reopen_count
    severity: .severity
    assignedTo: .assigned_to.link
    urgency: .urgency
    contactType: .contact_type
    createdOn: '.sys_created_on | (strptime("%Y-%m-%d %H:%M:%S") | strftime("%Y-%m-%dT%H:%M:%SZ"))'
    createdBy: .sys_created_by
    isActive: .active
    priority: .priority
  4. Click Save & Resync to apply the mapping.

Implementationโ€‹

You can delete ServiceNow incident by leveraging Port's synced webhooks and secrets to directly interact with ServiceNow's Table API.

Add Port secretsโ€‹

To add a secret to your portal:

  1. Click on the ... button in the top right corner of your Port application.

  2. Click on Credentials.

  3. Click on the Secrets tab.

  4. Click on + Secret and add the following secrets:

    • SERVICENOW_INSTANCE_URL - The ServiceNow instance URL. For example https://example-id.service-now.com.

    • SERVICENOW_API_TOKEN: A base64 encoded string of your servicenow credentials generated as:

      echo -n "your-username:your-password" | base64

Set up self-service actionโ€‹

  1. Head to the self-service page.

  2. Click on the + New Action button.

  3. Click on the {...} Edit JSON button.

  4. Copy and paste the following JSON configuration into the editor.

    Delete ServiceNow Incident (Click to expand)
    {
    "identifier": "delect_servicenow_incident",
    "title": "Delect ServiceNow Incident",
    "icon": "Servicenow",
    "description": "Deletes an incident from the ServiceNow incident table using a unique system ID",
    "trigger": {
    "type": "self-service",
    "operation": "DELETE",
    "userInputs": {
    "properties": {},
    "required": [],
    "order": []
    },
    "blueprintIdentifier": "servicenowIncident"
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "{{.secrets.SERVICENOW_INSTANCE_URL}}/api/now/table/incident/{{.entity.identifier}}",
    "agent": false,
    "synchronized": true,
    "method": "DELETE",
    "headers": {
    "RUN_ID": "{{ .run.id }}",
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": "Basic {{.secrets.SERVICENOW_API_TOKEN}}"
    },
    "body": {}
    },
    "requiredApproval": false
    }
  5. Click Save.

Now you should see the Delect ServiceNow Incident action in the self-service page. ๐ŸŽ‰

Create an automation to remove entity from Portโ€‹

Once the incident is deleted from ServiceNow, we want to automatically remove the corresponding entity in Port. To achieve this behaviour:

  1. Head to the automations page.

  2. Click on the + Automation button.

  3. Copy and paste the following JSON configuration into the editor.

    Delete ServiceNow incident in Port automation (Click to expand)
    {
    "identifier": "servicenow_incident_delete_sync_status",
    "title": "Remove Deleted Incident from Port",
    "description": "Removes the deleted entity in Port when after it is deleted from ServiceNow",
    "trigger": {
    "type": "automation",
    "event": {
    "type": "RUN_UPDATED",
    "actionIdentifier": "delect_servicenow_incident"
    },
    "condition": {
    "type": "JQ",
    "expressions": [
    ".diff.after.status == \"SUCCESS\""
    ],
    "combinator": "and"
    }
    },
    "invocationMethod": {
    "type": "WEBHOOK",
    "url": "https://api.port.io/v1/blueprints/{{.event.diff.after.blueprint.identifier}}/entities/{{.event.diff.after.entity.identifier}}",
    "agent": false,
    "synchronized": true,
    "method": "DELETE",
    "headers": {
    "RUN_ID": "{{.event.diff.after.id}}",
    "Content-Type": "application/json",
    "Accept": "application/json"
    },
    "body": {}
    },
    "publish": true
    }
  4. Click Save.

Now, whenever a user runs the Delete ServiceNow Incident action:

  1. The incident is deleted directly from ServiceNow via webhook.
  2. The corresponding entity in Port is automatically removed, keeping your catalog clean and consistent.