Create an issue in Jira Cloud when a case is updated in Salesforce


Get Started

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

About the template


This template demonstrates how to create an issue in Jira Cloud when a case status is updated in Salesforce. 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

TypeScriptOnSalesforceCaseStatusUpdatedEvent
Generic Event

README


๐Ÿ“‹ Overview

This template demonstrates how to create an issue in Jira Cloud when a case is updated in Salesforce.

๐Ÿ–Š๏ธ Workspace setup

  1. Create APIs: Configure an API connection for Jira Cloud or use an existing one.
  2. Configure parameters: Set the necessary parameters to match your requirements.
  3. Set up Salesforce event listener:
    • Follow the steps in the event listener setup instructions and include the following configurations:
      • Outbound message: Set up an outbound message, and add the Status and Subject fields.
      • Flow for the event trigger:
        • Trigger: Select Case as the object
        • Event: Choose "A record is updated"
        • Entry conditions: Set to All Conditions Are Met (AND), and also:
          • Field = Status
          • Operator = Is Changed
          • Value = True (global constant)

๐Ÿš€ Using the template

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.

API Connections


TypeScriptOnSalesforceCaseStatusUpdatedEvent

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;
}
Documentation ยท Support ยท Suggestions & feature requests