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 demonstrates how to create an issue in Jira Cloud when a case is updated in Salesforce.
Update the Case status in your Salesforce instance to trigger the event. If all required fields are complete, a new Jira Cloud issue will be created automatically.
import JiraCloud from "./api/jira/cloud";
import { SalesforceGenericEvent } from '@sr-connect/salesforce/events';
/**
* This function creates Jira Cloud issue from Salesforce event, when Case status is changed.
*
* @param event Object that holds Case is changed event data
* @param context Object that holds function invocation context data
*/
export default async function (event: SalesforceGenericEvent, 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 { PROJECT_KEY, ISSUE_TYPE_NAME } = getEnvVars(context);
// Case data from the event
const caseSubject = event.notifications.Notification.sObject['sf:Subject'];
const caseStatus = event.notifications.Notification.sObject['sf:Status'];
// Fetch project ID from provided key
const projectId = +(await JiraCloud.Project.getProject({
projectIdOrKey: PROJECT_KEY
})).id;
// Fetch issue type ID from provided type name.
const issueTypeForProjectId = (await JiraCloud.Issue.Type.getTypesForProject({
projectId
})).find(t => t.name.toLocaleLowerCase() === ISSUE_TYPE_NAME.toLocaleLowerCase()).id
if (caseSubject && caseStatus) {
// Create Jira Cloud issue with data from Salesforce event.
const issueCreated = await JiraCloud.Issue.createIssue({
body: {
fields: {
project: {
id: projectId.toString()
},
issuetype: {
id: issueTypeForProjectId
},
summary: `SF Case: ${caseSubject} - current status: ${caseStatus}.`
}
}
});
// Print out issue key of the newly created issue.
console.log(`Issue created: ${issueCreated.key}.`);
} else {
console.error('Case data is not presented in the event object.');
}
}
interface EnvVars {
PROJECT_KEY: string;
ISSUE_TYPE_NAME: string;
}
export function getEnvVars(context: Context) {
return context.environment.vars as EnvVars;
}