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).

  1. In Jira, go to Settings > Issues > Custom fields > Create custom field > Short Text (plain text only) and click Next.

  2. 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.

  1. Go to Project > Project Settings > Automation (left side panel) > Create Rule.

  2. 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

Field value changed screen with Fields to monitor for changes, Change type and For fields
  1. 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 https://www.salesforceben.com/salesforce-object-key-prefix-list/documentation provides information to help identify the prefix of the object you'll be working with.

smart values condition page with First value, Condition, and Second value fields
  1. 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.

  1. 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.

  1. 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

  2. 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).

  3. Copy the API token and encode it with the username. You can use this third-party site to encode it.

  4. In the website's text box, arrange the username and the token in the following format:

    • Jira Cloud:
      <username>:<APIToken>

    • Jira DC:
      <username>:<password>

  5. Click Encode and copy the result to the Jira Automation page.

  6. In the Headers section, set the Key name as Authorization.

  7. Set the Value by pasting the encoded data from Step 9 in the <encodedToken> portion of the text Basic <encodedToken>.

  8. Set the HTTP Method to PUT and select the Delay execution option.

  9. 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:

  1. 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.