Questions for Confluence license has expired.

Please purchase a new license to continue using Questions for Confluence.

Is there a way to map Jira labels and categories (custom field) between two Jira instances?

 
1
0
-1

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.

    CommentAdd your comment...

    1 answer

    1.  
      2
      1
      0

      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

      1. Oliver Robillo

        Thanks very much for this, Francis! I will give this a try.

      2. Oliver Robillo

        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?

      3. user-3fd1a

        You can traverse the labels using something like


        def targetLabel = replica.labels.find { it.label == "MyLabel" }
        def targetCategory = labelMap[targetLabel] ?: "DefaultCategory"



        If you provide some more details, we can provide some more examples

      CommentAdd your comment...