Forums

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

Set custom field based on calculation from another field

Rees_ Ian
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.
January 9, 2025

I have a Custom field which is a Select List MulitChoice.  The field is called "IanTestSelectListMultiChoice".   The multiple field values can each be categorized as CatA, CatB, CatC and CatD. And the Category is stored in another custom field called "IanTestSelectListSingleChoice".  The different values in the IanTestSelectListMultiChoice field each belong to one Category only (either CatA, CatB, CatC or CatD). However there is a hierarchy in the Categories cos CatA > Catb > CatC > CatD.

What I am trying to achieve is that when value changes in IanTestSelectListMultiChoice field, I want to automatically set the IanTestSelectListSingleChoice to the HIGHEST ranking category.

My thinking was to create two lookup tables - one to map Value to Category and then a second table mapping Category to a Rank value so that in a loop I can compare the Category Rank of each value and always select the highest ranked category until ultimately I can choose the highest rank category to set in the IanTestSelectListSingleChoice field .  But I have become stuck with this approach and am wondering if it is indeed possible. Any help would be much appreciated

 

Just to add, this would be possible with a complicated calculation but the mapping between value and category may occasionally change so having them in a lookup table makes it easy to modify the automation

script1.PNGlookuptable1.PNGlookuptable2.PNG

 

1 answer

1 accepted

2 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.
January 9, 2025

Hi @Rees_ Ian 

Short answer: based on what you show, there is no solution because the first table shows a many-to-many mapping of values-to-categories, and so multiple values could be returned with the same rank-hierarchy value, but only one is possible for a single-selection field.

Slightly longer answer, assuming there is an error in the scenario description: there is no simple solution to this scenario for an automation rule, and so you could use a high-maintenance automation rule (by rethinking how the tables are used or using a logic condition) or build this outside Jira as a service which the rule could call using the Send Web Request action.

Kind regards,
Bill

Rees_ Ian
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.
January 10, 2025

Hi Bill, Happy New Year to you and thanks for your response.  I think I tend to agree but wanted to check that I have described the scenario correctly.  A value in the "IanTestSelectListMultiChoice" field can only belong to ONE category.  But of course there are several different values in that "IanTestSelectListMultiChoice" field so potentially belonging to different categories.

The logic I am trying to achieve is

If Any of the Values in IanTestSelectListMultiChoice is CategoryW (highest rank) set the single value of IanTestSelectListSingleChoice  to "Category W"

ELSE

if any of the Values in IanTestSelectListMultiChoice is CategoryX (2nd highest rank) set the single value of IanTestSelectListSingleChoice  to "Category X"

ELSE

If any of the Values in IanTestSelectListMultiChoice is CategoryY (3rd highest rank) set the single value of IanTestSelectListSingleChoice  to "Category Y"

ELSE

If any of the Values in IanTestSelectListMultiChoice is CategoryZ (lowest rank) set the single value of IanTestSelectListSingleChoice  to "Category Z" 

I think my approach of iterating through each of the IanTestSelectListMultiChoice fields in turn is flawed because I would need to save the highest Category rank found so far on each iteration and I can't find a way of doing that

I am going to explore if a possible approach is to merge all the IanTestSelectListMultiChoice values into one string and then use some string matching to set the appropriate category in the IanTestSelectListSingleChoice field.

 

In fact as I type that in that seems pretty straightforward - I think I got stuck in a dead end with my original idea and ended up spinning wheels

Thanks 

 

 

Like Bill Sheboy likes this
Rees_ Ian
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.
January 10, 2025

In fact this is straightforward in the end just by getting all the values into a variable and then using conditional logic to test whether the string contains something and setting the category accordingly.  But your reply was helpful in just steering me way from the iterative method I was trying. 

The only thing I am stuck with is clearing the IanTestSelectListSingleChoice when IanTestSelectListMultiChoice is cleared.  As the custom field does not appear in the list of fields to edit when I choos edit issue, I am using Advanced field editing throughout. I have tried

{ "fields": { "IanTestSelectListSingleChoice": { "value": "" } } }

 

{ "fields": { "IanTestSelectListSingleChoice": { "value": null } } }

{ "fields": { "IanTestSelectListSingleChoice": { "value": "None" } } } but always get the message "

 

Specify a valid value for IanTestSelectListSingleChoice (customfield_14414))

Rees_ Ian
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.
January 10, 2025

I solved that last problem by temporarily adding IanTestSelectListSingleChoice  to my screen. that meant that when creating the automation, in edit Issue I could actually select the IanTestSelectListSingleChoice field rather than use Advanced field editing and I set the value to {{clear}}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events