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โ
- Complete the onboarding process.
- Access to your ServiceNow account with permissions to manage incidents.
- Install Port's ServiceNow integration.
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:
-
Go to the Data Sources page of your portal.
-
Select the ServiceNow integration.
-
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 -
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:
-
Click on the
...
button in the top right corner of your Port application. -
Click on Credentials.
-
Click on the
Secrets
tab. -
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โ
-
Head to the self-service page.
-
Click on the
+ New Action
button. -
Click on the
{...} Edit JSON
button. -
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
} -
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:
-
Head to the automations page.
-
Click on the
+ Automation
button. -
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
} -
Click
Save
.
Now, whenever a user runs the Delete ServiceNow Incident
action:
- The incident is deleted directly from ServiceNow via webhook.
- The corresponding entity in Port is automatically removed, keeping your catalog clean and consistent.