Create an incident in ServiceNow when an issue is created in Jira Cloud


Get Started

Not the template you're looking for? Browse more.

About the template


This template demonstrates how to create an incident in ServiceNow when an issue is created in Jira Cloud, and then adds a comment back to the Jira issue with the newly created incident number. Get started to learn more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnJiraCloudIssueCreated
Issue Created

README


๐Ÿ“‹ Overview

This template demonstrates how to create an incident in ServiceNow when an issue is created in Jira Cloud, and then adds a comment back to the Jira issue with the newly created incident number. Check out Jira Cloud and ServiceNow sync template for more comprehensive and ready-made solution.

๐Ÿ–Š๏ธ Setup

Set up the API connections and event listener for Jira Cloud and ServiceNow. You can either create new connectors or use existing ones.

๐Ÿš€ Usage

Create a new issue in your Jira Cloud instance. Once the event is processed, a new incident will be created in ServiceNow, and a comment containing the incident number will be added to the Jira issue.

API Connections


TypeScriptOnJiraCloudIssueCreated

import { IssueCreatedEvent } from '@sr-connect/jira-cloud/events';
import ServiceNow from "./api/servicenow";
import JiraCloud from "./api/jira/cloud";

/**
 * This function creates an incident in ServiceNow when an issue is created in Jira Cloud and then adds a comment with incident number to the newly created issue
 *
 * @param event Object that holds Issue Created event data
 * @param context Object that holds function invocation context data
 */
export default async function (event: IssueCreatedEvent, context: Context): Promise<void> {
    if (context.triggerType === 'MANUAL') {
        console.error('This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.');
        return;
    }

    try {
        // Create a new Incident in ServiceNow
        const incident = await ServiceNow.Table.addRecord({
            tableName: 'incident',
            body: {
                short_description: `${event.issue.key} -  ${event.issue.fields.summary}`
            }
        });

        // Add a comment to the Issue that was created to include the incident number
        await JiraCloud.Issue.Comment.addComment({
            issueIdOrKey: event.issue.key,
            body: {
                body: {
                    type: 'doc',
                    version: 1,
                    content: [{
                        type: 'paragraph',
                        content: [{
                            type: 'text',
                            text: `ServiceNow Incident: ${incident.result.number}`
                        }]
                    }]
                }
            }
        });

        console.log(`Incident created: ${incident.result.number}`);

    } catch (e) {
        console.log('Error while processing event', e)
    }
}

Documentation ยท Support ยท Suggestions & feature requests