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.
Template Content
This template listens for IssueCreated
events in Jira Service Management Cloud and creates an Assets object based on the event.
GetWorkspaceId
script manually.WORKSPACE_ID
variable in the Parameters
.CreateObjectSchema
script manually.Parameters
.Create a new issue in your JSM instance to trigger the event listener. An Assets object of the specified type will be created.
import JiraServiceManagementCloudAssets from "./api/jsm/cloud/assets";
import { getEnvVars } from './Utils';
/**
* This function generates JSM Assets object schema
*/
export default async function (event: any, context: Context): Promise<void> {
const {
WORKSPACE_ID,
CreateObjectSchema: {
OBJECT_SCHEMA_NAME,
OBJECT_SCHEMA_KEY,
OBJECT_SCHEMA_DESC,
// Names of the attributes that will be displayed, you can change these in Environment Variables if you wish
OBJECT_TYPE_NAME,
USER_ATTRIBUTE_NAME,
STATUS_ATTRIBUTE_NAME,
DESCRIPTION_ATTRIBUTE_NAME,
}
} = getEnvVars(context);
// Create object schema
const schemaResponse = await JiraServiceManagementCloudAssets.Object.Schema.createSchema({
workspaceId: WORKSPACE_ID,
body: {
name: OBJECT_SCHEMA_NAME,
objectSchemaKey: OBJECT_SCHEMA_KEY,
description: OBJECT_SCHEMA_DESC
}
});
// Create object type
const objectTypeResponse = await JiraServiceManagementCloudAssets.Object.Type.createType({
workspaceId: WORKSPACE_ID,
body: {
name: OBJECT_TYPE_NAME,
iconId: '1', // You can shoose icons here: https://<YOUR_INSTANCE_ADDRESS>/jira/servicedesk/assets/configure/global
objectSchemaId: schemaResponse.id
}
});
// Create reported attribute
const reporterAttribute = await JiraServiceManagementCloudAssets.Object.Type.Attribute.createAttribute({
workspaceId: WORKSPACE_ID,
objectTypeId: objectTypeResponse.id,
body: {
name: USER_ATTRIBUTE_NAME,
type: 2 // Chosen type of attribute is Jira User
}
});
// Create status attribute
const statusAttribute = await JiraServiceManagementCloudAssets.Object.Type.Attribute.createAttribute({
workspaceId: WORKSPACE_ID,
objectTypeId: objectTypeResponse.id,
body: {
name: STATUS_ATTRIBUTE_NAME,
type: 7 // Default Status type of the attributes, takes default statuses for JSM Assets
}
});
// Create description attribute
const descriptionAttribute = await JiraServiceManagementCloudAssets.Object.Type.Attribute.createAttribute({
workspaceId: WORKSPACE_ID,
objectTypeId: objectTypeResponse.id,
body: {
name: DESCRIPTION_ATTRIBUTE_NAME,
type: 0, // Chosen type of attribute is Default
defaultTypeId: 0 //Default type - Text
}
});
// Find all type attributes
const createdSchema = await JiraServiceManagementCloudAssets.Object.Type.getTypeAttributes({
workspaceId: WORKSPACE_ID,
id: objectTypeResponse.id
});
// From the type attributes find the name attribute
const nameAttribute = createdSchema.find(sch => sch.name === 'Name');
// Check if the name attribute was found
if (!nameAttribute) {
// If not, then throw an error
throw Error('Failed to find default name attribute id.');
}
// Print out newly created object IDs
console.log('Copy the following object IDs and paste them to corresponsing properties in OnJiraServiceManagementCloudIssueCreated script file', {
objectTypeId: objectTypeResponse.id,
attributes: {
nameAttributeId: nameAttribute.id,
reporterAttributeId: reporterAttribute.id,
statusAttributeId: statusAttribute.id,
descriptionAttributeId: descriptionAttribute.id
}
});
}
import JSMCloud from "./api/jsm/cloud";
/**
* This function prints out JSM Cloud workspace IDs
*/
export default async function (): Promise<void> {
const workspaceId = ((await JSMCloud.Assets.getWorkspaces()).values ?? []).map(w => w.workspaceId).join('\n');
console.log(workspaceId);
}
import { IssueCreatedEvent } from '@sr-connect/jira-cloud/events';
import JiraServiceManagementCloudAssets from "./api/jsm/cloud/assets";
import { getEnvVars } from './Utils';
/**
* The function creates JSM Assets object using data from JSM IssueCreated event.
*
* @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;
}
// The following variables can be defined by creating suggested object schema using CreateObjectSchema script
// If you wish to use your own schema, please write your own variables and pass them accordingly to createObject method below
const {
WORKSPACE_ID,
Event: {
OBJECT_TYPE_ID,
NAME_ATTRIBUTE_ID,
REPORTER_ATTRIBUTE_ID,
STATUS_ATTRIBUTE_ID,
DESCRIPTION_ATTRIBUTE_ID,
}
} = getEnvVars(context);
const createdObject = await JiraServiceManagementCloudAssets.Object.createObject({
workspaceId: WORKSPACE_ID,
body: {
objectTypeId: OBJECT_TYPE_ID,
attributes: [{
objectTypeAttributeId: NAME_ATTRIBUTE_ID,
objectAttributeValues: [
{
value: `Report from ticket ${event.issue.key}`
}
]
}, {
objectTypeAttributeId: REPORTER_ATTRIBUTE_ID,
objectAttributeValues: [
{
value: event.issue.fields.reporter?.accountId ?? ''
}
]
}, {
objectTypeAttributeId: STATUS_ATTRIBUTE_ID,
objectAttributeValues: [
{
value: '1' // 1 - Default status: "ACTION NEEDED"
}
]
}, {
objectTypeAttributeId: DESCRIPTION_ATTRIBUTE_ID,
objectAttributeValues: [
{
value: event.issue.fields.summary ?? 'No summary'
}
]
}],
}
});
console.log('JSM object', createdObject);
}
interface EnvVars {
WORKSPACE_ID: string;
CreateObjectSchema: {
OBJECT_SCHEMA_NAME: string;
OBJECT_SCHEMA_KEY: string;
OBJECT_SCHEMA_DESC: string;
OBJECT_TYPE_NAME: string;
USER_ATTRIBUTE_NAME: string;
STATUS_ATTRIBUTE_NAME: string;
DESCRIPTION_ATTRIBUTE_NAME: string;
}
Event: {
OBJECT_TYPE_ID: string;
NAME_ATTRIBUTE_ID: string;
REPORTER_ATTRIBUTE_ID: string;
STATUS_ATTRIBUTE_ID: string;
DESCRIPTION_ATTRIBUTE_ID: string;
}
}
export function getEnvVars(context: Context) {
return context.environment.vars as EnvVars;
}