We’re using Jira Software Cloud and Exalate. Is there a way to map labels (built-in field) and categories (custom field) between two Jira instances? We’d like to sync issues from one external Jira instance where they don’t use our custom-field categories, and map the labels they use to our categories.
Answer by Francis Martens (Exalate) on 13 September 2019
Hi Oliver Robillo
Thanks for raising the question in the community.
The use case you mention can be implemented as follows:
Send the labels by including them into the message
replica.labels = issue.labels
Process the incoming message
Here you will have to map the incoming label to the category
An example where there is only one label to process
def labelMap = [
"Incoming Label 1" : "Category 1",
"Incoming Label 2" : "Category 2",
"Incoming Label 3" : "Category 3",
]
/*
** Map the label to the target category, and revert to default if not found
** replica.labels is an array of labels
** replica.labels.first is the first label in the array
** replica.labels.first.label is the string that represents the label itself
** replica.labels?.first?.label
** the question marks avoid nullpointerexceptions
*/
def firstLabel = replica.labels?.first?.label
/*
** if the firstlabel is not found in the labelMap, default to DefaultCategory
*/
def targetCategory = labelMap[firstLabel] ?: "DefaultCategory"
/*
** Assign the found label to the category drop down custom field
*/
issue.customFields."Category".value = targetCategory
Let me know if this helps
Comments:
Oliver Robillo commented on 16 September 2019
Thanks very much for this, Francis! I will give this a try.
Oliver Robillo commented on 16 September 2019
Hi user-50445
What if there were multiple labels in an issue (which is often the case), and I needed to look for one particular label from the array so that I could map that to our category?
Francis Martens (Exalate) commented on 16 September 2019