Trouble syncing priority between ServiceNow and DevOps

Originally asked by Chris Lund on 06 October 2021 (original question)


When we try to send the priority from ServiceNow in the outgoing script to DevOps, the priority value is showing as the urgency value in the replica payload. How can we pull the correct priority value from ServiceNow to send and sync with DevOps?


Answer by Jack Handy on 07 October 2021

I just worked this out myself a few days ago. Hereā€™s what I did.

On the ServiceNow side:

// Outgoing
    replica.priority  = entity.priority

// Incoming:

//first set up a map between the two to translate the input from ADO into something SNOW could use:

def PriorityMap = [
    "1" : "1 - Critical",
    "2" : "2 - High",
    "3" : "3 - Moderate",
    "4" : "4 - Low"
    ]

// next get the input from ADO and map it to the appropriate  priority type for SNOW. // If you get something you don't expect then just call it "4 - Low"

    def targetPriority = PriorityMap[replica.priority.name] ?: "4 - Low" 
    entity.priority = nodeHelper.getPriority(targetPriority)

ADO side:

// Outgoing

    replica.priority   = workItem.priority

// Incoming
// same process in reverse, create a mapping for disparate data types:

def PriorityMap = [
    "1 - Critical" : "1",
    "2 - High" : "2",
    "3 - Moderate" : "3",
    "4 - Low" : "4",
    ]

// Use the PriorityMap to translate SNOW into ADO and then the helper to put it in the correct data type format

    def targetPriority = PriorityMap[replica.priority.name] ?: "4"
    workItem.priority = nodeHelper.getPriority(targetPriority) 
    

Thatā€™s what worked for me. Hope that helps!


Comments:

Chris Lund commented on 08 October 2021

Jack Handy Thank you for that piece of code, but we are still having issues in syncing the priorities. On the outgoing from SNow to ADO, the priority field is updating but only to P4, in the payload the priority value is still being sent as the urgency value. We have different values for urgency and priority, example urgency = ā€˜1 - Highā€™ and priority = ā€˜1 - Criticalā€™, so mapping these values isnā€™t working because it is sending a value we arenā€™t expecting so it always get set as 4.

Conversely on the incoming to SNow only the urgency is getting set, it will update the priority field if the urgency/impact matrix determines a new priority. I realize that we could and probably will just copy that matrix over to ADO and determine priority the same way, but now Iā€™m just curious if itā€™s even possible to send the actual priority value in the payload

Jack Handy commented on 08 October 2021

I was going at this the wrong way. I was able to reproduce this. I thnk itā€™s a bug.

On the second part:

You can send priority but I donā€™t think SNow will accept the input to that field as itā€™s ā€œcalculatedā€ from the other values.

Jack Handy commented on 08 October 2021

I reported this to them as a bug. In the meantime if you wanted to have some fun you could put together a matrix of possible values:

impact & urgency = priority
1 & 1 = 1 Critical
1 & 2 = 2 High
1 & 3 = 3 Moderate
2 & 1 = 2 High
2 & 2 = 3 Moderate
2 & 3 = 4 Low
3 & 1 = 3 Moderate
3 & 2 = 4 Low
3 & 3 = 4 Low

Then use a switch or if statement to build the correct value to send and use something like

if(entity.impact.contains(ā€œLowā€) && entity.urgency.contains(ā€œHighā€){
replica.priorityVal = ā€œ3 - Moderateā€
}

I havenā€™t tested this but I think it should work until this gets explained/fixed.

Francis Martens (Exalate) commented on 09 October 2021

I can confirm this was a bug.
We mixed up urgency and priority.

To keep backward compatibility we had to introduce

  • priorityValue (to reflect the priority field)
  • urgencyValue (to reflect the urgency field)

Check for this How to sync urgency and priority between ServiceNow and Jira
Which is pretty similar to the way it can be done between ServiceNow and Azure DevOps

Chris Lund commented on 12 October 2021

Francis Martens (Exalate) Thanks for that link, I was able to fix the priority issue and now it is syncing between the 2 systems using priorityValue. If you had not provided that I was planning on implementing something along the lines of what Jack Handy commented below. Thanks again for all your help!

Answer by Jack Handy on 14 October 2021

I notice that the other priority syncs that were working are not working now. Still trying to figure it out.
Syncing Incidents to Bugs still works with the fix above.
Priority for Enhancements in ServiceNow sync to Enhancements in Azure just fine.

The exact same configuration for other record types doesnā€™t work. I can sync from SNow to Azure but not the other way around. I used to be able to do this until the day before yesterday.

The code below shows the relevant code for two examples. One works and the other does not.

Azure Out:


replica.priority = workItem.priority
replica.priorityName = workItem.priority.name
...

Azure Incoming:
def PriorityMap = [
"1 - Critical" : "1",
"2 - High" : "2",
"3 - Moderate" : "3",
"4 - Low" : "4"
]
def my_priority = PriorityMap[replica.priority.name] ?: "4 - Low"
workItem.priority = nodeHelper.getPriority(my_priority) 
---------------------

ServiceNow Out:
if(entity.tableName == "rm_enhancement") {
   replica.priority = entity.priority
   ...
}
if(entity.tableName == "dmn_demand") {
   replica.priority = entity.priority
   ...
}

ServiceNow Incoming:
def PriorityMap = [
"1" : "1 - Critical",
"2" : "2 - High",
"3" : "3 - Moderate",
"4" : "4 - Low",
"5" : "5 - Planning"
]
if(entity.tableName == "rm_enhancement") {
   ...
   def targetPriority = PriorityMap[replica.priorityName] ?: "4 - Low"
   entity.priority = nodeHelper.getPriority(targetPriority)
}

if(entity.tableName == "dmn_demand") {
   ...
   def targetPriority = PriorityMap[replica.priorityName] ?: "4 - Low"
   entity.priority = nodeHelper.getPriority(targetPriority)
}

Comments:

Francis Martens (Exalate) commented on 19 October 2021

Hi Jack Handy

What is not working?
Can you check the targetPriority and the found priority with getPriority for the entities rm_enhancement, dmn_demand - and check if the provided provided priorities match the values allowed for this field

Please use

debug.error("Targetpriority = ${targetPriority}")

Answer by Jack Handy on 09 October 2021

Got the priority thing worked out. It took a while!

On the ServiceNow side:

Outgoing

concatenate the urgency and impact values together to make a unique identifier for each case.

if(entity.tableName == "incident") {
    replica.priorityName       = entity.impact + entity.urgency

    ...

}

On the Azure side:

Incoming

Create a map of possible combinations with the value they need to represent on the ADO side.

if(issueUrl.contains("incident")){
    //workitem.priority = nodeHelper.getPriority(replica.priority.name)
    workItem.summary = replica.summary
def PriorityConstructor = [
  "1 - High1 - High" : "1",
  "1 - High2 - Medium" : "2",
  "1 - High3 - Low" : "3",
  "2 - Medium1 - High" : "2",
  "2 - Medium2 - Medium" : "3",
  "2 - Medium3 - Low" : "4",
  "3 - Low1 - High" : "3",
  "3 - Low2 - Medium" : "3",
  "3 - Low3 - Low" : "4"
  ]
    my_priority = PriorityConstructor[replica.priorityName]
    workItem.priority = nodeHelper.getPriority(my_priority)
}

Iā€™m proud of this one. :smile:


Comments:

Francis Martens (Exalate) commented on 09 October 2021

Great approach to combine impact and urgency!

Jack Handy commented on 11 October 2021

Thanks. Iā€™m still new to a lot of this so even though this isnā€™t all thst ā€œfancyā€ itā€™s pretty fancy for me! (old community)

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.