Setting a value based on a labels (jira - > Azure)

Originally asked by Daniel Estermann on 21 April 2021 (original question)


We try to set the Area Iteration Path in Azure based on the Labels received from Jira on prem. If workItem.labels contains the Tag/label “Cockpit” then it should set the value for iterationPath to “xxx” else its “DGB” set it to “yyy”. Unfortuanatly I always get the default path…

Does anyone have a idea what i’m doing wrong? :wink:

Many thanks,

Daniel

if (workItem.labels.contains(“Cockpit”)) {
workItem.iterationPath = “ExtensionTest\\Cockpit”}
else if (workItem.labels.contains(“DGB”)) {
workItem.iterationPath = “ExtensionTest\\DGB”}
else {
workItem.iterationPath = “ExtensionTest\\Incidents”}


Answer by Francis Martens (Exalate) on 21 April 2021

You can use a 'debug statement to see what path is being followed like

if (workItem.labels.contains("Cockpit")) {
     debug.error("Should be cockpit because workItem.labels '${workItem.label}'")
     workItem.iterationPath = "ExtensionTest\\Cockpit"}
else if (workItem.labels.contains("DGB")) {
     debug.error("Should be DGB because workItem.labels '${workItem.label}'")
     workItem.iterationPath = "ExtensionTest\\DGB"}
else {
     debug.error("Is incidents because workItem.labels '${workItem.label}'")
workItem.iterationPath = "ExtensionTest\\Incidents"}

With this, when ADO receives a message from Jira, an error will be raised containing details about the branch taken and the value of the workItem.labels.

You will have to take it from there.


Comments:

Daniel Estermann commented on 22 April 2021

Hi Francis,

Thanks for the hint. Seems like the value in workItem.Labels is not what i expected. My understand was, that the workItem.labels is first mapped with the replica.labels and that I can then work with the mapped content (labels).

As I’m not a dev this is obviously wrong. (old community)

How do i put the content (labels) into a field where the script below can read it?

Many thanks for your help
Daniel

javax.script.ScriptException: com.exalate.api.exception.IssueTrackerException: Is incidents because workItem.labels ‘[com.exalate.basic.domain.hubobject.v1.BasicHubLabel@1081f]’

workItem.summary = replica.summary
workItem.description = replica.description
workItem.priority = replica.priority
workItem.labels = replica.labels
workItem.attachments = attachmentHelper.mergeAttachments(workItem, replica)
workItem.comments = commentHelper.mergeComments(workItem, replica)

if (workItem.labels.contains(“Cockpit”)) {
debug.error(“Should be cockpit because workItem.labels ‘${workItem.labels}’”)
workItem.iterationPath = “ExtensionTest\\Cockpit”}
else if (workItem.labels.contains(“DGB”)) {
debug.error(“Should be DGB because workItem.labels ‘${workItem.labels}’”)
workItem.iterationPath = “ExtensionTest\\DGB”}
else {
debug.error(“Is incidents because workItem.labels ‘${workItem.labels}’”)
workItem.iterationPath = “ExtensionTest\\Incidents”}

Francis Martens (Exalate) commented on 22 April 2021

Daniel Estermann

How does the label look like what is the output of the debug.error?