Pre requisites-
- ServiceNow Instance
- JIRA Instance
Steps:
- Get ServiceNow Instance
- Get JIRA instance
- Create a Project in JIRA
- Create Authentication token in JIRA
- Go to JIRA instance-> Go to account settings https://id.atlassian.com/manage-profile/profile-and-visibility
- Click on Security.
- Go to Create and Manage API tokens
- Click on Create API Token
Note: Please note down this API Key somewhere as it is visible only at the time of creation.These are the necessary settings to be done in JIRA in order to begin with Integration.
- Now in the ServiceNow instance, we need to create a Rest Message under System Web Services-> Outbound -> REST Message.
- Click on New. This will open a new form to enter the details of Rest Message.Name: provide the name for the Rest Message.Description: provide the details as in what all methods will be created from this Rest Message.Endpoint: endpoint comprises of the instance name with the Rest API version the 3rd party application is providing.Authentication Type: provide the authentication type used by the API. (Basic/OAuth 2.0)
- Select the Authentication Type as Basic. A field “Basic auth profile” will be visible, specify the profile or create new.
- To create new Basic auth profile.
- Click on the search option from the field the following widow will open -> Click on New.
- Provide the following detailsName: Name given to the profileUsername: The email address used to create the JIRA instancePassword: This will be the API Key that we created in the JIRA -> Security. (Refer from step: 4. iv.)
- Click on the search option from the field the following widow will open -> Click on New.
- Click on Default Get.,
- Provide the endpoint and HTTP Request in headers
- Accept: application/json, Content-Type: application/json
- Click on Test
Integration Usecase
If any new Incident for enhancement request is raised in ServiceNow, create a JIRA User Story and store the JIRA ID on the Incident for that particular enhancement.
- Create the category and subcategory in ServiceNowCategory:RequestSubcategory:Enhancement
- Go to System Web Services -> Outbound -> Rest Message.
- Open the Rest Message that we created. In this Rest Message we will add a new HTTP Method in order to achieve the integration.
- In this scenario, we need to create a JIRA Story with the ServiceNow’s Incident ID, Description and Short Description.
- Provide the following details in the new HTTP Method:
- Name: Create JIRA story
- HTTP Method: POST
- Endpoint: https://yourinstancenamehere.atlassian.net/rest/api/3/issue/
- Authentication type: Inherit from Parent
- In HTTP Request add the following two headers:
- Accept: application/json
- Content-Type: application/json
- In the Content field, enter the payload that we need to send while creating the JIRA StoryFollowing is the request body I have used:{“fields”: {
“project”:
{
“key”: “SER”
},
“summary”: “${shortDescription}”,
“issuetype”: {
“name”: “Story”
},
“customfield_10037”: “${incidentNumber}”,
“description”: {
“type”: “doc”,
“version”: 1,
“content”: [
{
“type”: “paragraph”,
“content”: [
{
“text”: “${description}”,
“type”: “text”
}
]
}
]
}
}
}
Note: “${shortDescription}”, “${incidentNumber}”, “${description}” are the variables created to pass the data dynamically.
- Create following new Variable Substitutions
a. Name: descriptionEscape type: No escaping Value: Blank b. Name: incidentNumberEscape type: No escaping Value: Blank c. Name: shortDescriptionEscape type: No escaping Value: Blank - You can test, this method by providing some test data in the variables and Click on “Test” from the Related Links.
- We now need to create a Business rule on Incident Table which will trigger the call to this Rest Message.
- Details of the Business Rule:Name: Create Jira StoryTable: Incident
When to Run:
When: after Insert, Update
Filter Conditions:
Category is Request
Subcategory is Enhancement
Advanced:
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
try {
var createJiraStory = new sn_ws.RESTMessageV2(‘SNOW JIRA Integration’, ‘Create JIRA Story’);
createJiraStory.setStringParameterNoEscape(‘description’, current.description);
createJiraStory.setStringParameterNoEscape(‘shortDescription’, current.short_description);
createJiraStory.setStringParameterNoEscape(‘incidentNumber’, current.number);
var response = createJiraStory.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var getJiraUserStoryID = JSON.parse(responseBody);
var jiraUserStoryID = getJiraUserStoryID.key;
current.setValue(‘u_jira_id’, jiraUserStoryID);
current.update();
} catch (ex) {
var message = ex.message;
}
})(current, previous);
Note: The code to mention in this business rule can also be obtained from the Rest message
Go to the desired Method you have created. For example, Create Jira Story, in the Related Links you will find the link “Preview Script Usage”, this link gives the sample code you can use in the BR.
- A field called, “JIRA ID” is created on ServiceNow Incident form, which will be updated after the Story is created in JIRA. The code in the business rules updates the JIRA ID from the response received.