Forums

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

Calculate value based on user answers on Jira automation

Norman Ruta October 6, 2022

Hi,

Got a form with radio fields assigned to Jira custom fields. Both have values A,B,C. And started to build automation with multiple IF blocks which should work like that:

First block:
IF custom filed 1 = A then custom field SUM = SUM +3

IF custom filed 1 = B then custom field SUM = SUM +2

IF custom filed 1 = C then custom field SUM = SUM +1

Second block

IF custom filed 2 = A then custom field SUM = SUM +3

IF custom filed 2 = B then custom field SUM = SUM +2

IF custom filed 2 = C then custom field SUM = SUM +1

and I have 8 block like that.

Now the problem is that SUM doesn't bring expected values. If every field was set to A I get 30 instead of 24. If every field was set to C I get 1 instead of 8.

In an IF block I'm checking if custom field is equal to answer A and then I'm using Edit issue field which looks like this:

{{issue.custom field SUM}}+3

I saw that there are some issues with handling multiple IF blocks here:
https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Multiple-IF-statements-that-are-not-mutually-exclusive/qaq-p/1225204

Tried also adding re-fetch between every IF block but that brought even higher result. This came up after reading this:
https://community.atlassian.com/t5/Jira-Software-questions/Automation-for-Jira-How-to-call-one-rule-from-another/qaq-p/1354980

I also wanted to trigger another rule and yes I have checked in another rule ability to trigger but I can't see any component that could actually trigger rule. 

I even tried branches which unfortunately do not provide IF blocks so I tried simple Branch, check which answer was provided and then add appropriate value but this works only one time so giving the limit of 65 components and being unable to trigger another rule I'm back to square one.

Can anyone help me with this?

Best
Norman


2 answers

0 votes
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.
October 6, 2022

Hi @Norman Ruta -- Welcome to the Atlassian Community!

From what you have described, I suspect you can do this in one rule, in one step, using conditional logic and a math expression.

For example...you note multiple custom fields with single-select alphanumeric values and each of those values mapping to a numeric value to add to the sum.

Let's assume all of your custom fields have values.

{{#=}}0+{{#if(equals(issue.customField1,"A"))}}3+{{/}}{{#if(equals(issue.customField1,"B"))}}2+{{/}}{{#if(equals(issue.customField1,"C"))}}1+{{/}}0{{/}}

How this works...

  • The outer structure is to hold all of the math values to sum up
  • The tricky part is handling any null values...Which is why we add the leading "0+" and the trailing "0" inside of the math operation to sum the values.
  • Then for each custom value/option...
    • We test if the value equals what you expect, and if it does supply the number to add...followed by a plus sign

Please repeat the pattern, as needed, for your other custom fields.  If all of your custom fields do not have values, you may either add conditional logic or use some defaults in the field values.

Kind regards,
Bill

Norman Ruta October 7, 2022

Hi @Bill Sheboy,

Thanks for your reply. Although I figured it with a use of Labels I see that the solution might be more elegant. 

For handling null I have 4th value which I haven't mentioned. I wanted to keep it more simple here. The 4th option that user can chose from radio buttons is "Not applicable" and that one can add 0 to the SUM.

However I'm looking at your proposition

{{#=}}0+{{#if(equals(issue.customField1,"A"))}}3+{{/}}{{#if(equals(issue.customField1,"B"))}}2+{{/}}{{#if(equals(issue.customField1,"C"))}}1+{{/}}0{{/}}

and I was trying to do something similar but always received errors with JSON.

Can I ask how can apply smart values you have presented? Meaning which component etc.

This is how I'm starting this automation:

First rule I have is triggered by a new issue and then it checks if the type of the issue is the one I need. 

Since I want SUM filed to be visible in portal and I can't lock it from editing the first thing automation is doing is checking it agains being larger than 0 or not empty and if so then zero it down.

And I guess this is the place where your proposition should go but I don't have a clue which component to use.

Norman

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.
October 7, 2022

My understand was you were setting some custom field (e.g. your Sum value), and so the smart value expression may be entered directly with issue field edit for the rule.

As the values for the source custom fields could change (or the Sum be tampered with  manually :^) you may need a few rules to do the same calculation, or to trigger it:

  • when an issue is created
  • when one of the source fields or the Sum changes
  • etc.

I recommend first creating the smart value expression in a text editor, and then pasting it into the rule.

0 votes
Norman Ruta October 6, 2022

Hi again,

I have figure this out. I can actually "trigger" another rule. Which is not a trigger per se. Next rule has to check if:

- Labels field has changed
- Then if Labels contains a label that was introduced in earlier Rule
- Then if Issue type is the one it should work on (just in case)

So in simple terms one needs to juggle with Labels and change them every iteration. 

I hope this helps someone else because I couldn't find it well explained!

And Atlassian team, can you give it some thought for future? I had to create 8 rules to achieve this.

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