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 automate a single instance by listening to events from and then connecting back to the same instance, in this case creating a new sub-task in Jira DC (or server) when the parent issues assignee is updated.
Pick an issue and change the assignee, after successful event processing a sub-task should be created for the issue you changed the assignee for.
import { IssueUpdatedEvent } from '@sr-connect/jira-on-premise/events';
import JiraOnPremise from "./api/jira/on-premise";
/**
* This function demonstrates how to enhance a single instance by listening events from and connecting back to the same instance,
* in this case creating a new sub-task if the parent issues's assignee changes.
*
* @param event Object that holds Issue Updated event data
* @param context Object that holds function invocation context data
*/
export default async function (event: IssueUpdatedEvent, 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;
}
// Check if the issue update was related to assignee change
if (!event.issue.fields?.issuetype?.subtask && event.changelog?.items?.[0]?.field === 'assignee') {
// Get the old assignee from the event
const oldAssigneeName = event.changelog.items[0]?.fromString ?? 'Unassigned';
// Get the new assignee from the event
const newAssigneeName = event.changelog.items[0]?.toString ?? 'Unassigned';
// Get the project ID from the event
const projectId = event.issue.fields?.project?.id;
// Get the parent issue ID from the event
const parentId = event.issue.id;
// Log out what we're about to do
console.log('Creating new sub-task', {
parentIssueKey: event.issue.key,
oldAssigneeName,
newAssigneeName
});
// Find all the issue types
const issueTypes = await JiraOnPremise.Issue.Type.getTypes();
// Find the sub-task issue type
const issueType = issueTypes.find(it => it.name === 'Sub-task' && (!it.scope || it.scope.project?.id === projectId));
// Check if the issue type was found
if (!issueType) {
// If not then throw an error
throw new Error('Issue type not found');
}
// Finally create the sub-task
const issue = await JiraOnPremise.Issue.createIssue({
body: {
fields: {
project: {
id: projectId
},
issuetype: {
id: issueType.id
},
parent: {
id: parentId
},
summary: `Assignee changed from ${oldAssigneeName} to ${newAssigneeName}`
}
}
});
// And log out the issue key of the sub-task
console.log(`Created new sub-task: ${issue.key}`);
}
}