Servicenow to Jira Bi-directional Integration with UI action to create issue for existing incidents

Shivam Techlene
Tera Guru

Servicenow to Jira Bi-directional Integration

 

NOTE: Maybe this post is missing something due to servicenow post format restrictions. Kindly check the attached document for better reference

 

Requirement:

Integrate Servicenow with Jira bi-directionally so that when an incident is created in servicenow, then an issue should be created on Jira having required data from the incident ticket of servicenow. And consecutively the same incident ticket should be updated with the Jira Issue Id and connection status on the respective fields of the incident.

     On updating an incident, if there is a jira issue connected then it should also be updated on the Jira side. And when a Jira issue updated, the incident connected to it should be updated in servicenow as well.

 

Steps to Produce:

Installing Required Plugins

  1. On the application navigator, type plugins and click on plugins under system definition application.
  2. Search for Jira Spoke(sn_jira_spoke) and click on install.

Configure Incident Form

  1. Open an incident form and open the form menu by clicking the hamburger menu or by right clicking on the header.
  2. Hover on configure and click on form layout.
  3. Under Section list, click on “New” and create a new section named “JIRA”.
  4. Under Create New Field, create one true/false field named “Jira Connection” and one string field named “Jira Key” and save it.

Configure Connections & Credentials

  1. Search for ‘credentials’ under filter navigator and click on credentials under connections & credentials category of IntegrationHub application.
  2. Click on Basic Auth Credentials
  3. Give a name to your credential record.
  4. Give the email Id that is used to login for your Jira instance.
  5. For the password you need to put API Key from Jira.(Stept to get API token from Jira given below)
    1. Open your Jira Instance.
    2. Click on the settings icon beside the profile icon.
    3. Click on Atlassian account settings.
    4. Open the security tab and click on “Create and manage API tokens”.
    5. Click on Create API Token
    6. Give a name to your token and click on create.
    7. Copy the token key and keep it handy somewhere.
  6. Now go back to your servicenow instance and paste the copied token into the password field of your credential.
  7. Save the credential record.
  8. Open the filter navigator and search for connections and click on connections under connections & credentials category of IntegrationHub application.
  9. Click on “New” and select HTTP(s) connection.
  10. Give a name to your connection.
  11. Select the credentials you’ve created.
  12. Select “sn_jira_spoke_jira” under connection alias.
  13. Give your Jira account base URL under Connection URL. For example: “https://account_name.atlassian.net/”.
  14. Click on save.
  15. Go to Connection & Credential Aliases under Connections & Credentials category of IntegrationHub Application from application navigator and open the record “Jira”.
  16. Verify that your connection and credential records are linked together in the related list.

Create Integration Flows:

Flow for creating issue in Jira when incident is created in servicenow

  1. Search for flow designer on application navigator. Click on “Flow Designer” under the process automation application.
  2. Create a new flow for creating issues on jira. Flow properties will be: 
    1. Name: Of your choice.
    2. Application: Jira Spoke 
    3. Protection: None
    4. Run As: User who initiates the session
  3. Click on submit
  4. Click on Add a trigger
    1. Trigger: Record Created
    2. Table: Incident
    3. Condition: Created By - is not - system
    4. Run Trigger: Once 
  5. Click On Done
  6. Click on “ Add an Action, Logic or subflow” and select “Action”
  7. Select “Create Issue” under Jira (Action and Connection Alias will be auto-populated)
  8. Select Create Issue action properties as follows:
    1. Project Key: “The one you’ve created on your Jira instance”
    2. Issue type: Task/Submit a request or Incident
    3. Summary: Trigger - Record Created -> Incident Record -> Short Description
    4. Description: Trigger - Record Created -> Incident Record -> Description
    5. Priority: As per required
  9. Click on Done
  10. Click on “ Add an Action, Logic or subflow” and select “Action”
  11. Select “Update Record” Under Servicenow Core Action
  12. Drag Incident record data pill from the data pane on the right side or select “Trigger - Record Created -> Incident Record” from data pill picker
    1. Table: auto populated as incident
    2. Click on add fields value and add fields as follows 
      1. Correlation Id: Create Issue -> Issue -> Id
      2. Jira Connection: True
      3. Jira Id/Key: Create Issue -> Issue -> Id
  13. Click on Done
  14. Click on save on the top right corner.
  15. Once saved, Click on activate on the top right corner.
  16. Now test the flow by creating a new incident in servicenow. An issue should be created in Jira with the same parameters passed in the flow.

 

Jira Webhook Setup

  1. Go to application navigator and search “Jira”
  2. Open “Jira Webhook Registries” under “Jira” Application
  3. Create a new registry by clicking on “New”
  4. Enter a desired Name
  5. You can select any given token or create a new token for yourself. Process of creating new token:
    1. Click on search button beside Token field and click on new on the token verification window.
    2. Give and name and enter the token key that you’ve created in Jira in the token field and save the record.
  6. Click on the callback URL button on the webhoot registry record.
  7. Copy the webhook  Callback Url populated as info message on the top of the record.
  8. Open your Jira instance, go to the settings icon beside profile icon and click on “System”
  9. Locate Webhooks in the left pane and click on it.
  10. Click on “Create a Webhook”. Give it a relevant name paste the callback url copied from servicenow in the URL field.
  11. Make sure the status is selected to enabled
  12. Scroll down and Make Issue(updated) checkbox under the “Issue related Events” as TRUE.
  13. Click on Create.

Setup Jira Webhook Routing Policy

  1. Go to application navigator and search “Webhook”
  2. Click on “ Jira Webhook Routing Policies” under Jira Webhooks application. It will open Decisions list
  3. Open “Default Decision” Record and make sure you are under “Jira Spoke “ application scope.
  4. Click on the search icon beside the answer field, change the referenced record of the Document field  to the subflow you’ve just created
  5. Click Ok and update the Decision record
  6. Now go back to your subflow and open the properties.
  7. Set Run as to System User and click on Update
  8. Now verify/test  the subflow by updating the Issue record in Jira, that has been created by the ServiceNow incident.

Subflow for updating incident in servicenow on updating the issue in Jira

  1. Go to Flow Designer in servicenow
  2. Open the “Process Jira Webhooks” OOTB subflow.
  3. Click on three dots on the top right corner to open flow actions menu and click on copy subflow.
  4. Give a suitable name to your subflow and click on Copy.
  5. Keep the “Subflow Inputs & Outputs” as it is.
  6. Click on the (+) below the Log and select Action
  7. Search look up and select “Look Up Record” under Servicenow Core Spokes
  8. Configure the Look Up Record action as follows:
    1. Table: Incident
    2. Conditions: Correlation Id - is - Subflow Inputs -> Issue -> Id
  9. Click on Done
  10. Click on the (+) below Look up Incident Record and select Action
  11. Search update and select Update Record under Servicenow Core Spokes
  12. Configure the Update Record action as follows:
    1. Record: Drag Incident Record data pill under Lookup Record from data pane on the right.
    2. Table: Auto populated
    3. Fields:
      1. Description - Subflow Inputs-> Issue -> description
      2. Short Description - Subflow Inputs-> Issue -> summary
    4.  Add other fields too if required, like this and click on Done
    5. Save the subflow and publish it from the top right corner.

Flow for updating issue in Jira when it’s incident is updated in Servicenow

  1. Open the flow designer and Click on New and select Action
  2. Action Input: 
    1. Label: Additional fields
    2. Name: additional_fields (auto populated)
    3. Type: String
    4. Mandatory: True
  3. Click on (+) below Inputs in the left pane And search for Script and select Script under Utilities.
  4. Script Step Values:
    1. Required Runtime: Instance
    2. Input Variables:
      1. Name: Additionalfields
      2. Value: Drag Additional Fields data pill from Input Variables in data pane.
    3. Script:

 

(function execute(inputs, outputs) {
    // ... code ...  
    var nameValues = JSON.stringify(inputs.Additionalfields);
    var obj;
    nameValues = JSON.parse(JSON.parse(nameValues));
    var encodedQuery = "";
    gs.info("Type of nameValues: " + typeof nameValues);
    var keys = (Object.keys(nameValues));
    for (var i = 0; i < keys.length - 1; i++) {
        encodedQuery += "" + keys[i] + "=" + nameValues[keys[i]] + "^";
    }
    encodedQuery += "" + keys[i] + "=" + nameValues[keys[i]];
    outputs.encoded_query = encodedQuery;
})(inputs, outputs);

 

  • Output Variables:
    1. Label: encoded_query
    2. Name: encoded_query
    3. Type: String
    4. Mandatory: False
  • Open Outputs below Error Evaluation and set the values as follows:
    1. Encoded_query: Drag encoded_query data pill from Script Step data pane.
    2. Action Statue: Leave Null
  • Save and Publish the Action.
  • Now Create a new flow to update the Jira Issue
  • Trigger Values:
    1. Trigger: Updated
    2. Table: Incident
    3. Conditions:
      1. Correlation Id - is not empty &&
      2. Updated By - is not - system
      3. Run Trigger: For each Unique Change
  • Click on (+) and select Action
  • Search “generate” and select generate_autofields under Jira spokes.
  • Generate_additionalfields data: 
    1. Additional Fields:

 

{
"Description" : "Trigger - Record Updated➛...➛Description​",
"Summary" : "Trigger - Record Updated➛...➛Short description​"
}

 

  • Click on Done.
  • Save and Activate the Flow
  • Test the flow by updating an incident on servicenow which is already connected with the JIRA issue.

 

 

UI Action to create Issue in Jirae for existing incidents of servicenow

  1. Search for “Ui Action” in filter navigator
  2. Click on “UI Actions” under “System UI” application
  3. Click on New and enter the UI action properties given below:
    1. Name: As per requirement
    2. Table: Incident
    3. Active: True
    4. Show Insert: False
    5. Show Update: True
    6. Form Button: True
    7. Condition: current.u_jira_connection == false
    8. Script:

 

 

(function() {
    try {
        //scope_name.flow_name;
        var flowName = 'global.snow_to_jira_integration_flow';
        var inputs = {};
        inputs['current'] = current; // current GlideRecord Object
        inputs['table_name'] = 'incident';
// sn_fd.FlowAPI.executeFlow(flowName, inputs); // Execute Synchronously
   sn_fd.FlowAPI.startFlow(flowName, inputs);  // Execute Asynchronously
        action.setRedirectURL(current); // Redirect to current page
    } catch (ex) {
        var message = ex.getMessage();
        gs.error(message);
    }
})();

 

 

             9. Save the UI Action.

**************************

 

If you've found this information valuable and effective, I would greatly appreciate your gesture of marking it as both helpful and correct. Your acknowledgment fuels the collaborative spirit of our community. Thank you for being an active participant in our shared knowledge journey!

 

Thanks & Regards,
Shivam Jaiswal
5 REPLIES 5

dwatson
Tera Contributor

@SHIVAM JAISWAL Do you know if this approach will work if Jira isn't hosted in the cloud and has a URL without the 'atlassian.net' in it? For example... https://account_name.org?  

Hello @dwatson ,

 

No this won't work for a non-cloud/on-premise Jira instance. For the on-premise Jira, one of the way that I know is you need to use mid server configuration and user that mid server in your connection record in servicenow to authenticate.

 

Please mark helpful and correct if my response is correct to your question.

 

dwatson
Tera Contributor

Thanks @SHIVAM JAISWAL Shivam Jaiswal! This is super helpful.

Anil Dronadala
Tera Contributor

Hello @Shivam Techlene 

 

I'm not able to see the 'generate' option to select the generate autofields under the Jira Spoke in flow designer. Can you please guide me on this.

  • Search “generate” and select generate_autofields under Jira spokes.
  • Now Create a new flow to update the Jira Issue
  • Trigger Values:
    1. Trigger: Updated
    2. Table: Incident
    3. Conditions:
      1. Correlation Id - is not empty &&
      2. Updated By - is not - system
      3. Run Trigger: For each Unique Change
  • Click on (+) and select Action
  • Search “generate” and select generate_autofields under Jira spokes.
  • Generate_additionalfields data: 
    1. Additional Fields: