How to auto-associate a Salesforce record with a Jira issue upon Jira issue creation in Jira DC
Problem
Currently, the connector cannot automatically link a Salesforce record with a Jira issue when it’s 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.
Compatibility: This method works with both standard Jira and Jira Service Management (JSM).
This guide focuses exclusively on one-to-one associations.
Instructions
Part 1: Create a Jira Custom Field
Create a new Jira text custom field to add the Object ID. This custom field must be added to the Create screen of the Issue Type. You can also add it to the View and Edit screens (optional).
Navigate to Settings > Issues > Custom fields .
Click Create custom field select Short Text (plain text only) and click aNext.
Name the field, for example,
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: Create 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 Object.
Go to Project > Project Settings > Automation (in the left panel).
Click Create Rule.
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 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 as follows
Jira DC:
<JiraBaseURL>/rest/api/2/issue/{{issue.key}}/properties/com.servicerocket.jira.cloud.issue.salesforce.associations
Before proceeding further, create an API token using a user with the correct permissions for the project, based on the Manage API tokens for your Atlassian account article (this step is not required for Jira Data Center).
Copy the API token and encode it with the username. You can use this third-party site to encode it.
In the website's text box, arrange the username and the token in the following format:
Jira DC:
<username>:<password>
Click Encode and copy the result to the Jira Automation page.
In the Headers section, set the Key name as
Authorization.Set the Value by pasting the encoded data from Step 9 in the
<encodedToken>portion of the textBasic <encodedToken>.Set the HTTP Method to
PUTand select the Delay execution option.Set the Web Request body as Custom data and use the following JSON file in the Custom data field. A Case Object is used in this example.
{ "associations": { "{{CaseID}}": { "son": "Case", "viewOnly": false, "autoPush": true, "autoPull": true } }, "ids": "{{CaseID}}", "types": "Case" }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 Object 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.