Syncing Service Now RITM variables to Jira Cloud

Question

We have multiple custom fields in Service Now that appear on the Details Entered tab (see below):

Can these be synchronised with Jira Cloud?

These are variables, and yes they can be but slightly more complicated.

@mathieu do you have something handy to send these out to Jira handy please?

Dear @cbrooks

This is a very nice use-case and perfectly possible with Exalate.

Are you using the script mode?

If yes, can you please use this code in the outgoing sync;

  Map<String, String> buildVariablesMap(String requestItemNumber) {
    def limitResult = 20

    def Map<String, Object> result = [:]
    def response 
    
    
    // lookup all options associated to this number
    
    response = httpClient.get("/api/now/table/sc_item_option_mtom?sysparm_query=request_item.number=${requestItemNumber}&sysparm_limit=${limitResult}")    
    if (!response || !response.result) return null  // ignore if there are no results
    
    
    // For each of the options, lookup corresponding question and add to the result map
    response.result.each { 
        def optionSysId = it.sc_item_option?.value
        
        def optionDetails = httpClient.get("/api/now/table/sc_item_option/${optionSysId}")
        if (!optionDetails || !optionDetails.result) return // ignore - the option itself is not found
        
        def itemOptionNew = optionDetails?.result?.item_option_new?.value
        if (!itemOptionNew) return  // ignore - link to question not found
        
        def itemOptionNewDetails = httpClient.get("/api/now/table/item_option_new/${itemOptionNew}")
        if (!itemOptionNewDetails || !itemOptionNewDetails.result) return // ignore - the question is not found
        
        def value1
        if(itemOptionNewDetails.result.question_text.equals("List of Reviewers?"))
        {
            def allref=optionDetails.result.value
            String[] str
            def allEmail=[]
      str = allref.split(',')
      
      for( String s : str )
        {
          allEmail.add(nodeHelper.getReference("sys_user", "sys_id", s)?.email)
        }
value1=allEmail.join(",")
    }
    else
    {
        value1=optionDetails.result.value
    }
        result.put ( itemOptionNewDetails.result.question_text,value1)        
}
    return result
}


if(entity.tableName == "sc_req_item") {
    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
    replica.variables      = buildVariablesMap(entity.key)
  
}
if(entity.tableName == "sc_task") {

    replica.summary = entity.short_description
    replica.key = entity.key
    replica.component = "Other/Comp"
    replica.description = entity.description
    replica.priority = entity.priority
    replica.attachments = entity.attachments
    replica.customField = "Other"
    def ritmKey = entity.request_item?.display_value.toString() // If the entity is a Catalog Task
    replica.variables = buildVariablesMap("${ritmKey}")
}

Please let me know how it goes.
Thank you and have a great day.

Kind regards,
Mathieu Lepoutre

Hi

Many thanks for your prompt response. I am getting the following in my local entity sync status on Service Now:

{
“version”: {
“major”: 1,
“minor”: 14,
“patch”: 0
},
“hubIssue”: {
“number”: “RITM171610”,
“type_name”: “sc_req_item”,
“opened_by”: {
“display_value”: “Colin Brooks”,
“link”: “https://nhbcdev.service-now.com/api/now/v2/table/sys_user/75bec7ab1b785d100a3cb8c8dc4bcb1b”,
“scala$collection$convert$JavaCollectionWrappers$MapWrapper$$underlying”: {}
},
“u_item_state”: “Pending”,
“state”: “Open”,
“voters”: ,
“fixVersions”: ,
“internalMap”: {
“number”: “RITM171610”,
“type_name”: “sc_req_item”,
“opened_by”: {
“display_value”: “Colin Brooks”,
“link”: “https://nhbcdev.service-now.com/api/now/v2/table/sys_user/75bec7ab1b785d100a3cb8c8dc4bcb1b”,
“scala$collection$convert$JavaCollectionWrappers$MapWrapper$$underlying”: {}
},
“u_item_state”: “Pending”,
“state”: “Open”
},
“labels”: ,
“customKeys”: {},
“entityProperties”: {},
“components”: ,
“attachments”: ,
“customFields”: {},
“eventTriggerContext”: {},
“description”: “”,
“watchers”: ,
“key”: “RITM171610”,
“summary”: “Tableau Access Request”,
“comments”: ,
“workLogs”: ,
“affectedVersions”:
},
“issueUrl”: “MyIT MyIT (DEV)”
}

I don’t think the script is working?

Kind regards

Colin

Dear @cbrooks

Can you please change the function to this one:

// This function will fetch all the variables in the given RITM
Map<String, String> buildVarsMap(requestItemNumber, limitResult) {
    def Map<String, Object> result = [:]
    // lookup all options associated to this number
    //debug.error(requestItemNumber.toString())
    def optionList = httpClient.get("/api/now/table/sc_item_option_mtom?sysparm_query=request_item.number=${requestItemNumber}&sysparm_limit=${limitResult}")   
   // debug.error(optionList.toString())
    if (!optionList || !optionList.result) return null  // ignore if there are no results
    // For each of the options, lookup corresponding question and add to the result map
    optionList.result.each {
        def optionSysId = it.sc_item_option?.value
        def optionDetails = httpClient.get("/api/now/table/sc_item_option/${optionSysId}")
        if (!optionDetails || !optionDetails.result) return // ignore - the option itself is not found
        def itemOptionNew = optionDetails?.result?.item_option_new?.value
        if (!itemOptionNew) return  // ignore - link to question not found
        def itemOptionNewDetails = httpClient.get("/api/now/table/item_option_new/${itemOptionNew}")
        if (!itemOptionNewDetails || !itemOptionNewDetails.result) return // ignore - the question is not found
        def optionsDetails = getUserNames(optionDetails.result.value) ?: optionDetails.result.value
        result.put ( itemOptionNewDetails.result.question_text, optionsDetails)       
    }
    return result
}

And then you can reference it in sc_req_item codeblock like so:
replica.variables = buildVarsMap(entity.key, 20)

Thank you and have a great day.

Kind regards,
Mathieu Lepoutre

Hi Mathieu

We have tried the script and we are still unable to export the variables. We have used the debug error and get the following:

for :

def optionList = httpClient.get(“/api/now/table/sc_item_option_mtom?sysparm_query=request_item.number=${requestItemNumber}&sysparm_limit=${limitResult}”)
debug.error(optionList.toString())

Is this where the issue is?

Dear @cbrooks

Yes, that’s correct.
Can you please comment out that statement?

Thank you and have a great day.

Kind regards,
Mathieu Lepoutre

Hi

When we ran the new function you provided we were not getting any results. So we tried uncommenting the debug errors to see where it was going wrong. Not sure how how to proceed?

Can you please review the Replica on the incoming side. Does it contains the replica.variables object?