Template Content
About the template
About ScriptRunner Connect
What is ScriptRunner Connect?
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.
This template demonstrates how to create a new request in Jira Service Management Cloud when an alert is created in Opsgenie with a configurable priority mapping.
Parameters
and configure parameters to meet you needs.SERVICE_DESK_NAME
variable by providing the JSM project name.SERVICE_DESK_REQUEST_TYPE_NAME
variable by providing the JSM Request type name.PRIORITY_MAPPING
variable.JSM_SUMMARY_PREFIX
variable to add certian prefix that will be used in the summary field in JSM. Example: Created from Opsgenie Alert: <Message from alert>
.import JiraServiceManagementCloud from "./api/jsm/cloud";
import { AlertCreatedEvent } from '@sr-connect/opsgenie/events';
export default async function (event: AlertCreatedEvent, 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;
}
const { SERVICE_DESK_NAME, SERVICE_DESK_REQUEST_TYPE_NAME, JSM_SUMMARY_PREFIX, PRIORITY_MAPPING } = getEnvVars(context);
// Find Service Desk ID
const serviceDesks = await JiraServiceManagementCloud.Servicedesk.getServicedesks();
const serviceDeskId = serviceDesks.values?.find(desk => desk.projectName?.localeCompare(SERVICE_DESK_NAME, 'en', { sensitivity: 'base' }) === 0)?.id;
if (!serviceDeskId) {
throw new Error(`Failed to find Service Desk ID. Please check if project name is correct: ${SERVICE_DESK_NAME}.`);
}
// Find Request Type ID
const serviceDeskTypes = await JiraServiceManagementCloud.Request.Type.getTypes({
serviceDeskId: [+serviceDeskId]
});
const requestTypeId = serviceDeskTypes.values?.find(type => type.name?.localeCompare(SERVICE_DESK_REQUEST_TYPE_NAME, 'en', { sensitivity: 'base' }) === 0)?.id;
if (!requestTypeId) {
throw new Error(`Failed to find Request Type ID. Please check if Request Type Name is correct: ${SERVICE_DESK_REQUEST_TYPE_NAME}.`);
}
const calculatedPriority = PRIORITY_MAPPING[event.alert.priority];
// Create request in JSM
const createdRequest = await JiraServiceManagementCloud.Request.createRequest({
body: {
requestFieldValues: {
description: event.alert.description ?? '',
summary: JSM_SUMMARY_PREFIX ? JSM_SUMMARY_PREFIX + event.alert.message : event.alert.message,
priority: { name: calculatedPriority } // need to add to the Request type user gonna use
},
requestTypeId,
serviceDeskId,
}
});
console.log(`Created JSM Request ${createdRequest.issueKey} from Opsgenie alert ${event.alert.message} - Alert ID: ${event.alert.alertId}.`);
}
type OpsgeniePriorityId = string;
type JsmPriorityLevel = string;
interface EnvVars {
SERVICE_DESK_NAME: string;
SERVICE_DESK_REQUEST_TYPE_NAME: string;
PRIORITY_MAPPING: Record<OpsgeniePriorityId, JsmPriorityLevel>
JSM_SUMMARY_PREFIX?: string;
}
export function getEnvVars(context: Context) {
return context.environment.vars as EnvVars;
}