Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to extract a list of labels from an incoming webhook, and add them to a created ticket?

Edited

Hey everyone, I've got 2 instances of Jira and I'm using the Send Web Request automation action to post to the other, where I have an Incoming Webhook setup to parse the issue data, and create a ticket in the 2nd instance.

I want to then have them somewhat in sync, so I'm writing the trigger issues key to a custom field, then using another pair or Request/Webhooks to write the new issues key back to the 1st instance ticket in a similar custom field there. Then I can use that as a smart value on the webhook URL to target specific tickets.

I have tried for the life of me to work out how to take {{webhook.Data.fields.labels}} and turn it into a list in some way to then add to the new ticket, without ending up with either an amalgamated mega-label, or an error because of whitespace.

The goal is that the 2nd instance should always match whatever happens to the 1st instances ticket. So if it has 5 labels, so should the 2nd ticket. If I remove one from the 1t ticket, it should get removed from the 2nd.

Any ideas? I feel like I'm probably going about this wrong.

1 answer

1 accepted

0 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 01, 2023

Hi @Graeme Baker 

First thing, are you using Jira Cloud?  If so I recommend reading this article announcing a change to the packaging / licensing model for automation rules.  Unless you are on the Premium or Enterprise level license I suspect the rules you describe will be impacted and have cost implications for synching the instances.

https://community.atlassian.com/t5/Automation-articles/Introducing-our-new-packaging-model-for-Jira-Cloud-Automation/ba-p/2446099

Back to your question...

Please review the layout / contents of that webhook data, and then try split the label field using the split() function.  That will give you a list of values that then could be iterated over to add them.  I recommend doing this in one step, either with a single field edit or using advanced edit with JSON; otherwise multiple edits could cause problems in the rule.

Kind regards,
Bill

Thanks Bill! We're on data center LTS for both instances, so not a worry (yet!)

I can use the split function to turn the labels into an array after the data has been received, but on 9.4.5, it won't let me use this as a smart value in the Edit Issue/Labels section

When logging {{webhookData.fields.labels.split(" ")}}, this returned the array as expected.

Is there a way to do this as a single field edit, or do I need to work out how to iterate over this in the Advanced edit and construct the JSON? I've been trying to research, as I'm fairly green with advanced editing, but no luck so far.

jira.png

I got almost there. I tried the following, after reading this https://community.atlassian.com/t5/Marketplace-Apps-Integrations/How-to-copy-multi-value-field-in-using-Advance-Options-in/qaq-p/769692

 

{

    "fields": {

        "labels": {{webhookData.fields.labels.split("_").asJsonStringArray}}

    }

}

 

I get a proper list of labels, but they are all encased in square brackets.

Ah, think I cracked it, no need for the split, with the .asJsonStringArray! That seems to do the trick.

I'm sure I'm missing some cases here potentially, around special characters perhaps.

What do you think? This was the final code, as I always want the source issue to be authroative on what the labels should be, and it be a one way sync

{

    "fields": {

        "labels": {{webhookData.fields.labels.asJsonStringArray}}

    }

}
Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 02, 2023

Well done!  That was the second approach I was describing.

As you want to synch (not incrementally add / remove) labels, this should work.  And as this is going from the Labels field as a source, I do not believe you need handling for special characters.

Thanks Bill. I might try to work out how to sync back and forth later, but this solves the problem I have today :) 

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events