Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation - Looping over predefined possible values of a field using smart values

Dd
Contributor
February 9, 2023

Hi,

Is there a way in automation to loop through all possible values of a custom field and act upon each value?

For example, if for field PARTS I have  3 options - A,B,C then I would like automation to run over the three values in a loop, perform a JQL which uses that value (A, thenB, then C) and based on the JQL list perform an operation.

Thanks 

1 answer

1 vote
Kian Stack Mumo Systems
Community Champion
February 15, 2023

@Dd

 

The process is very similar to  what you and I worked out in the other thread (perhaps you no longer need this? ). Regardless, here is what the process would be.

  1. Make a rest call to the custom field in question to get all of possible values
  2. Branch on each value.
  3. Execute a JQL based on the value you've extracted.

Here's how it would work in practice.

 

Make the rest call

The rest call you want to make is this one  - https://<yourdomain>.atlassian.net/rest/api/3/field/customfield_<YOUR CUSTOM FIELD ID>/context/<YOUR CUSTOM FIELD CONTEXT>/option.

 

To find the pieces of information required (fieldID and context ID), you'd need to be a system admin. Go to administration -> Issues -> Custom Fields.  Search for the custom field you want to get the options for. If you edit/configure the custom field, you'll find the ID in the web address at the very end. 

To get the  context ID, you'll need to edit the context, and look for the ID in the URL. It'll be found after the string fieldConfigSchemeId=.

Once you have collected those pieces of information, it's a good idea to build out your URL and paste it into your browser to validate that the  rest endpoint is properly constructed. If it is, you're good to proceed to the next part of the process - generating an API token for the automation to use. 

To use the API token, you'll need to encode it with the string <youremail>:<yourAPIToken> via  base64 encoding. You can use this website for that purpose.

 

Once you have the rest string constructed and the API token generated, you can start building the automation rule.

 

The automation rule will start with whatever trigger you want (in my case manual),  and then the very next step will be to make the rest call. Add a "Send web Request" action.

It should look like this once fully configured:

Screen Shot 2023-02-15 at 11.14.43 AM.png

 

The string that will go in the Authorization header will be "Basic <your encoded key>".

 

Once you have the Web request set up, you can move onto the next step - Branch on each value.

 

Branch on each value

This should be fairly simple to do. To branch on each value, simply use the advanced  branching condition and then pass it this smart value - {{webresponse.body.values.value}}.

Screen Shot 2023-02-15 at 11.19.06 AM.png

 

At this point, all you need to do is run the JQL

Execute a JQL based on the value you've extracted

Simply use the lookup issues action and pass the variable name from the advanced branching into your JQL. In my case, it would look like this -

cars in ({{car}}).

Cars is the name of the custom field I am searching against (and made the call to get the options for), and car is the variable name i defined in my branching conditions.

 

I hope this helps!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events