Skip to main content
How to integrate ServiceNow and Jira easily
Share on socials

How to integrate ServiceNow and Jira easily

Follow the steps below, or skip straight to the video demonstration at the bottom of the page, to learn how to use our built-in connectors to integrate ServiceNow with Jira Cloud.

Create and authorise your connections

First, create the connections to your tools from the Connectors tab. ScriptRunner Connect’s managed connections securely handle the authentication process for you.
  1. From the top right of the ScriptRunner Connect Connectors screen, click "create new".
  2. You can now see all of the tools we currently support for managed connections and a generic connector option to connect to any tool with a HTTP-based API. Select the Jira Cloud application.
  3. Name the connection and click "authorise".
  4. ScriptRunner Connect will guide you through a custom connection process relevant to your selected tool. In this case, you can choose the Jira Cloud instance you want to use from the authorise for site dropdown, then click "accept".
  5. Now, back in ScriptRunner Connect, select the URL of your chosen site and click "confirm". Once authorised, click "save" so you can start using your connector.
  6. Let's repeat the process for ServiceNow's connector. Click "create" and choose the ServiceNow tool.
  7. Name the connection and click "authorise".
  8. The on-screen instructions displayed are specific to ServiceNow, so follow them to authorise the connection.
  9. Click "save", and your connection is ready to use.
A screenshot of the instructions to configure connectors on ScriptRunner Connect

Create a workspace to host your scripts

Now the connections have been made, we'll create a workspace for scripting our integrations.
  1. On the left-hand side menu, click on "workspaces".
  2. Click "create new".
  3. Name your workspace and click "create".
  4. The page will redirect to the user interface for the workspace.
A screenshot of the user interface for the workspace

Configure your event listener

We will now create a simple script that:
  • Listens to ServiceNow for new incidents.
  • Replicates the new incident information to a Jira issue.

What is an event listener?

An event listener allows you to listen for events triggered by external services. In this case: new ServiceNow incidents.
To listen to ServiceNow:
  1. Click on the "create new event listener” + button.
  2. Select the ServiceNow tool.
  3. On the listener event type dropdown, choose "generic event", and the new script name will automatically generate.
  4. On the uses connector dropdown, choose the "ServiceNow" connector.
  5. Click "save". This will now listen for that event on ScriptRunner Connect.
  6. At this point, we can configure ServiceNow to send that event to ScriptRunner Connect. The pop-up walks you through the process, so follow these steps.

Setting up your scripts

Now that the listener is configured, we have two scripts to set up.
1. We have added what is called an Interface which allows us to tell the script what format the data from ServiceNow will take, and gives us the ability to access that data using the editor's autocomplete. We created the interface like this:
interface ServiceNowCreateIncidentEvent {
title: string,
eventType: string,
description: string,
incident: string,
comments: string
}
2. Tell the editor to use this interface for the event data from ServiceNow by adding it here:
export default async function(event: ServiceNowCreateIncidentEvent, context: Context): Promise<void> {
3. Go into ServiceNow and click "create" to create a new incident.
4. In the Short Description Field, enter a short description and add any comments in the additional comments box, then click "submit".
5. Go back to ScriptRunner Connect, and in the code editor console at the bottom of the screen, you can see that the event has been detected and the information you've configured in ServiceNow has been sent over.
Manually triggering Script "OnServiceNowGenericEvent" for "Generic Event" Event Listener with invocation ID: 01H512T1QZGAA5CV45H3HGFW3
Abort Invocation
Generic Event event triggered
{
"title": "incidentCreated",
"eventType": "generic_triggered",
"description": "Testing Desc",
"comments": "Testing comments",
"incident": "INC0010029"
)
{
"invocationId": "01H512T1QZGAA5CV45HY3HGFW3",
"environment": {
"uid": "01H14EG7F87DPMG90G17CM3T07",
"name": "Default"
},
"triggerType": "MANUAL_EVENT_ LISTENER",
"rootTriggerType": "MANUAL_EVENT_LISTENER",
"startTime": 1689032394712,
"availableMemory": 300,
"timeout": 889999
)
Screenshot showing event-triggered code
6. You can access the description in the scripting section because we've applied the interface. Go the the script ScriptRunner Connect created for you and type 'event' and from the options, click "description".
We are now listening to ServiceNow, and we have access to the information that ServiceNow is going to send to us. The next step is sending that information to Jira.

Sending information to Jira

First, we will create an API connection.
1. Click on the "add API Connections" + button and select Jira Cloud.
2. In the edit API connection menu, choose the connector you created earlier from the uses connector dropdown. Don't worry about authentication password tokens, as we configured those earlier.
3. Click "save", and you will see the connector has been added to the workspace.
4. Next, we want to add this API connection to the Script. To do this, select "import API connection".
5. Select the Jira Cloud API connection we set up earlier from the API Connection down. The Import Name will automatically complete.
6. Click "import" and the API connection will pull through to the Jira Cloud variable.
import JiraCloud from './api/jira/cloud';

What is an API connection?

API connections allow you to call external services APIs. In our example below we’re calling Jira Cloud.
Now that we have imported the Managed Connection, we will use this to create an issue in Jira with the information that we have from ServiceNow.
In order to do so, we need to get the correct Project ID, and Issue Type ID, as these are required by Jira's createIssue API endpoint.
1. Firstly, we use the Managed API to call the getProject API endpoint to get the Project WEB, and then extract its ID.
const project = await JiraCloud.Project.getProject ({
projectId0rKey: 'WEB'
});
const projectId = project.id;
2. Then we use the getTypesForProject endpoint, passing the Project ID we just extracted, to get all issues types available for Project WEB, and we search the list that is returned from this call to find the Issue Type "story" and extract the ID of that issue type.
const issueTypesForProject = await Jiracloud. Issue.Type.getTypesForProject({
projectId: Number(projectId)
})
const issueTypeld = issueTypesForProject.find(t => t.name.toLocaleLowerCase () ===
'story').id
3. Now that we have this information, we can pass it into the createIssue endpoint, along with additional information from the ServiceNow ticket.
await JiraCloud.Issue.createIssue({
body: {
fields: {
issuetype: {
id: issueTypeId
},
project: {
id:projectId
},
summary: `$event.incident} - ${event.description} - ${event. comments}`
}
}
})
We have now created an API call that will create a Jira issue whenever an incident is created in ServiceNow.
4. There's one more step: we want to capture the response for this call so we can understand and add error checking or error handling. To do that, we need to store it in a variable.
const jiraResponse = await JiraCloud.Issue.createIssue({
body: {
fields: {
issuetype: {
id: issueTypeld
},
project: {
id:projectId
},
summary: '${event.incident} - ${event.description} - ${event.comments}'
}
}
})
5. That will now store the response from the API call in the variable jiraResponse. We can log out this response as follows:
console.log(jiraResponse)
6. I have also included an await that tells the script to pause here and stop executing until we get a response back from the Jira API to handle that response correctly.
const jiraResponse = await JiraCloud.Issue.createIssue({
body: {
fields: {
issuetype: {
id: issueTypeld
},
project: {
id:projectId
},
summary: `${event.incident} - ${event.description} - ${event.comments}`
}
}
})
7. Save the script.
8. Go to ServiceNow and create a test incident.
9. Go back to ScriptRunner Connect and check the log. You should see the event and execution have been picked up.
10. Go to Jira and refresh the page. You should see a new ticket has been created using the information in your ServiceNow test incident!

Try it now

There's a free forever plan, and Managed Connectors for more than 20 of your favourite tools!
Published on 13th November, 2023
Authors
Bobby Bailey
Bobby Bailey
Share this tutorial