How to auto-associate a Salesforce Object to a Jira issue upon Jira issue creation.
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: Creating 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).
In Jira, go to Settings > Issues > Custom fields > Create custom field > Short Text (plain text only) and click Next.
In this example, the name of the field is
Case ID
.
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 Object.
Go to Project > Project Settings > Automation (left side panel) > Create Rule.
In the first component, select the Field value changed option and set it as follows:
Fields to monitor for changes:
Case ID
Change type:
Any changes to the field value
For:
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 with
Second 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 Listdocumentation 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:
CaseID
Smart value:
{{fieldChange.toString}}
This helps update the JSON file in the web request.
Click on next > Add Component > IF: Add a condition > {{smart values}} condition and set the component as follows:
First value:
{{CaseID.length()}}
Condition:
equals
Second 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:
<JiraBaseURL>/rest/api/3/issue/{{issue.key}}/properties/com.servicerocket.jira.cloud.issue.salesforce.associations
Jira Server:
<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 Cloud:
<username>:<APIToken>
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
PUT
and 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.