How to auto-associate a Salesforce record with a Jira issue upon Jira issue creation in Jira Cloud
Problem
Currently, the connector cannot automatically link a Salesforce Object with a Jira issue at the moment the Jira issue is created. However, by leveraging the capabilities of the Jira REST API, you can implement automation within the project to facilitate the auto-association process.
To make the automation work, manually add the Salesforce Object ID in a custom field when creating the Jira issue. This method is also compatible with Jira Service Management (JSM).
This guide focuses exclusively on one-to-one associations.
Instructions
Part 1: Create a Jira Custom Field
Jira Automation allows us to automatically send a web request to edit the entity property of the Jira issue and then associate the Salesforce record.
In Jira, go to Settings > Work Items > Fields > Create new field:
Field type: Short Text (plain text only)
Name: In this example, the name of the field is
Case ID.
Add this field to your Create screen for the relevant Issue Type.
(Optional) Add the field to the View and Edit screens.
Part 2: Creating the Jira Automation
Jira Automation allows us to automatically send a web request to edit the entity property of the Jira issue and then associate the Salesforce record.
Go to Project > Project Settings > Automation (in the left panel).
Click Create Rule.
In the first component, select the Field value changed option and set it as follows:
Fields to monitor for changes:
Case IDChange type:
Any changes to the field valueFor:
Create issue
Click Add Component > IF: Add a condition > {{smart values}} condition. This ensures that our agents/customers add the correct ID of the configured object. In this example, the Case Object type is used.
First value:
{{issue.<customField_Id>}}Condition:
Starts withSecond Value:
Object ID prefix
Ensure you utilize the field ID corresponding to the field you created on your instance in Part 1 of this documentation. To find the Custom Field ID, refer to How to find the ID for custom field(s).
The
Salesforce Object Key Prefix List | Salesforce Bendocumentation provides information to help identify the prefix of the object you'll be working with.
Click Next, then Add an action > Create variable and set the component as follows:
Variable name:
CaseIDSmart value:
{{fieldChange.toString}}
This helps update the JSON file in the web request.
Click Next > Add Component > IF: Add a condition > {{smart values}} condition and set the component as follows:
First value:
{{CaseID.length()}}Condition:
equalsSecond value:
18
This helps to verify that the added ID is the correct length.
Set the Web Request URL with the URL according to your Jira environment:
Jira Cloud EU:
eu-sfjc.integration.appfire.app/external/api/association?allowUpsert=trueJira Cloud Rest of the World:
https://sfjc.integration.appfire.app/external/api/association?allowUpsert=true
In a new tab, navigate to Jira > Apps > Connector for Salesforce > Connections > click the 3 dots next to your connection > API Access Token > Select the REST API token lifespan and copy the token shown at the bottom.
Go back to the automation and in the Headers section, set the Key name as
Authorization.Set the Value as
JWT <REST API Token>Set the HTTP Method to
POSTand select the Delay execution option.Set the Web Request body as Custom data and use the following JSON file in the Custom data field. In this example, a case object type is used.
{ "jiraIssueId": "{{issue.id}}", "son": "Case", "soid": "{{CaseID}}", "viewOnly": false, "autoPush": true, "autoPull": true }The web request component up to this point looks like the following:
Click Next > Add Component > THEN: Add an action > Re-fetch issue data.
Overview of the final automation:
Now, if you add the Salesforce Object ID within the Case ID field after creating a Jira issue, the automation associates that record with the created Jira issue.
This auto-association won’t trigger the default post-actions; you’ll need to manually push the information to Salesforce.