By integrating Jira and ServiceNow, teams can fetch related SLA records within a ServiceNow incident and sync them in a user-defined Jira issue field, enabling them to track SLA information and ensure timely incident resolution.
In this blog post, we will see how to implement this use case using an integration solution called Exalate.
So let’s jump right in!
The following are the use case requirements:
Note: You can choose to populate the SLA information in any kind of Jira field you want. For this use case, we have considered a user-defined field called ‘SLA Info’.
Syncing an incident from ServiceNow to Jira is pretty straightforward and can be achieved easily.
However, syncing the SLA information to the Jira issue needs to be handled carefully.
An incident triggers (creates) an SLA record under two conditions:
Once, the SLA record is created, it must automatically be synced to the Jira issue in a user-defined field. Therein lies the real challenge; to find the correct Jira issue to add the SLA information.
Also, state changes in the SLA record must update the SLA details on the Jira side.
The use case is complex, so we must find a solution that handles this complexity easily.
And we have just the right solution for you.
Exalate is a bi-directional, fully customizable integration solution that helps integrate applications like Jira, ServiceNow, Salesforce, Zendesk, GitHub, Azure DevOps, etc.
We opted for Exalate to execute the use case because of the following reasons:
Note: You can learn more about Exalate through its Academy videos.
Note: You can learn more about setting up a connection by referring to the Getting Started guide or the Jira ServiceNow integration guide.
After setting up the connection, you must configure the sync rules, which are Groovy-based scripts that determine which information to exchange between Jira and ServiceNow.
You can access these rules by clicking the ‘Configure Sync’ button after the connection is established or by editing the connection.
The ‘Rules’ tab is where you’ll find the scripts we discussed earlier. They exist in both Jira and ServiceNow.
The ‘Outgoing sync’ determines what information is sent from the source to the destination, while the ‘Incoming sync’ specifies how to receive information from the source.
Let’s see the actual scripts required to implement this use case.
Remember, the scripts in the ‘Rules’ section provide some default behavior, like syncing comments, descriptions, etc. We must add our own scripting rules for the functionality we want to implement.
As such, from ServiceNow, we send the SLA information in the ‘Outgoing sync’.
The code:
class SlaRecord {
String name
String breach_time
String stage
String linkValue
}
if(entity.tableName == "incident") {
replica.key = entity.key
replica.summary = entity.short_description
replica.description = entity.description
replica.attachments = entity.attachments
replica.comments = entity.comments
replica.state = entity.state
def RelatedSlaRecords = []
def limitResult = 20
// lookup all related SLA records
def response = httpClient.get("/api/now/table/task_sla?sysparm_query=task.number=${entity.key}&sysparm_limit=${limitResult}")
if (!response || !response.result) return null
// For each SLA record, lookup corresponding value in contract_sla //table
// and collect all the data required within the RelatedSlaRecords array
response.result.each {
SlaRecord temp = new SlaRecord()
temp.breach_time = it.planned_end_time
temp.stage = it.stage
temp.linkValue = it.sla.value
def slaRecord = httpClient.get("/api/now/table/contract_sla/${it.sla.value}")
temp.name = slaRecord.result.sys_name
RelatedSlaRecords.add(temp)
}
replica.slaResults = RelatedSlaRecords
}
Note: You can pick up any SLA information via Exalate and sync it to the other end.
In the code above, we run an API query on the ‘task_sla’ table to fetch the related SLA records for that incident. After doing this, you can pick up the breach time, stage, and SLA value.
However, if you want to pick up the actual SLA name, you need to run another API query to the ‘contract_sla’ table. From there, you can fetch the actual SLA name.
We then package all of this within an object called ‘RelatedSlaRecords’ and send it to the other side.
Also, it’s possible that you can have more than one SLA. The idea is to then use an array to populate all the SLA objects and send them to Jira.
The job, on the other side, is relatively easy. All we need to do is to unravel the array that comes from the ServiceNow end.
We need to run a loop and iterate over all the fields from the array of objects sent from the ServiceNow side. Then display it in a user-defined ‘SLA Info’ field.
The code:
if(firstSync){
issue.projectKey = "UD"
// Set type name from source issue, if not found set a default
issue.typeName = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
}
issue.summary = replica.summary
issue.description = replica.description
issue.comments = commentHelper.mergeComments(issue, replica)
issue.attachments = attachmentHelper.mergeAttachments(issue, replica)
issue.labels = replica.labels
issue.customFields."SLA Info".value = ""
for(int i=0; i<replica.slaResults?.size; i++){
issue.customFields."SLA Info".value += "Name: ${replica.slaResults[i].name} \n Breach Time: _${replica.slaResults[i].breach_time} \n State: ${replica.slaResults[i].stage} \n\n"
}
You don't need any modifications on the Jira outgoing and ServiceNow incoming sides.
Let’s run the program and see the output.
Begin by creating a simple incident.
Set it in such a way that it triggers two SLA records.
The incident priority is now high and assigned to a specific user. And SLA records are created.
Both the SLA records must be synced to the Jira instance.
After syncing, the Jira side looks like this.
Remember, you can change the state of the SLA anytime. For instance, by changing it to ‘Cancelled’, you can see the updated SLA state in the Jira ‘SLA Info’ field.
By integrating platforms, modern businesses look to stay competitive and responsive to customer needs. The use case we demonstrated is proof of why integration tools will become even more critical in enabling successful collaboration between teams in the near future.
Want to know if Exalate is the right solution for your business? It is just a click away!
Syed Majid Hassan -Exalate-
0 comments