Forums

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

How to set a value using smart values and math with lookup lists

Leeland
Contributor
August 24, 2021

I'm trying to do a point spread auto calculation for a selection list with smart values.

 

List values are field multi-select items which users select when they create/edit their tickets.

 

Example:

Solution Change Type:

 - Software

 - Network

 - Content

 - Content in Software

 - etc.

 

Can't get the syntax right. What I want is my value if the item is selected and a zero if it is not selected.

 

Trigger: When value changes for "Solution change type" change

Action: Edit issue fields > Story Points

Example of desired calculation.

{{#math}}
IF(exists({{issue.Solution Change Type.get(0).value}}),2,0) +
IF(exists({{issue.Solution Change Type.get(1).value}}),1,0) +
IF(exists({{issue.Solution Change Type.get(2).value}}),1,0) +
 IF(exists({{issue.Solution Change Type.get(3).value}}),1,0)
{{/}}

 

I've tried a number of variations but I either end up with ' + + + + +' or 

 

Error rendering smart-values when executing this rule:
Unknown function 'Software' at position 15: IF(exists(Software (new or changes)),1,0) + IF(exists(Content Changes (in software code)),1,0) + IF(exists(),1,0) + IF(exists(),1,0) + IF(exists(),1,0) + IF(exists(),1,0) + IF(exists(),1,0) + IF(exists(),1,0) + IF(exists(),1,0) + IF(exists(),1,0) + IF(exists(),1,0)
My two issues are:
1. Getting the IF to work so I get one value on success and the zero otherwise.
2. The positional arguments are not fixed, even though the list field is. If only the last item is selected it is returned for the get(0) instead of its field position of get(10).

2 answers

1 accepted

1 vote
Answer accepted
Leeland
Contributor
August 25, 2021

This can be done in one step with a field edit

 

{{#math}}
{{issue.Solution Change Type.size|0}}
+ IF({{issue.Solution Change Type.join("_").indexOf("CHC Software")}}>=0,2,0)
+ IF({{issue.Solution Change Type.join("_").indexOf("On-Prem Infra")}}>=0,3,0)
+ IF({{issue.Solution Change Type.join("_").indexOf("Content Changes (outside software code)")}}>=0,1,0)
{{/}}

 

We just added up the values and then found specific items we wanted to count more than 1 point for (giving weight to those kinds of tickets).

 

Not precise, but good enough.

 

Thanks!

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.
August 24, 2021

Hi @Leeland 

If I am understanding your question, you want to sum values when items from your multiple-select field are selected AND it appears that some of those values have different summing values.  Is this correct?  If so...

Yes, you are correct: get() returns a value from a smart value list, and for your field it will only return selected choices...not the entire list, 0 to n-1, with a setting of "on" and "off".

So you probably have limited options for Jira Server automation: 

  • Sum the values based upon the number of selections, {{issue.Solution Change Type.size|0}} and then use a condition to add more for your special cases
  • Use if/else clauses and re-fetch to repeatedly increment your field with each selection.  This will make the rule very...very...slow. (>1 second for each refetch probably)

Best regards,
Bill

Leeland
Contributor
August 24, 2021

Assume I want to do it the really hard way. Can you give me a snippet to make that work? This is something we can let take a long time in the background and doesn't happen very often.

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.
August 24, 2021

Okay, perhaps something like this:

  • trigger: some trigger you want, such as the Solution Change Type changing
  • action: edit Story Points to clear the field (or set to 0)
  • action: re-fetch
  • if/else condition...
    • condition: Solution Change Type field contains Software
    • action: edit Story Points relevant for Software to add your value
    • action: re-fetch
  • if/else condition...
    • condition: Solution Change Type field contains Network
    • action: edit Story Points relevant for Network to add your value
    • action: re-fetch
  • ... and so forth

 

I have also seen community posts where people "bundle" data, storing the incrementor in the field definition and summing them later.  (DBAs dislike that :^)  For example:

  • Software: 1 unit
  • Network: 2 unit
  • Content: 1 unit
  • etc.

You may then get all of the values and sum them in one step in a rule, using a regular expression to extract the values and list functions to sum them up.

Good luck!

Leeland
Contributor
August 24, 2021

@Bill Sheboy 

 

Thanks, that almost works. I built this:

Screen Shot 2021-08-24 at 3.33.16 PM.png

 

But, Story Points is being set to 3 instead of the expected 4.

 

Screen Shot 2021-08-24 at 3.35.58 PM.png

 

I might have figured out a single pass with this style:

{{#math}}
IF({{issue.Solution Change Type.join("_").indexOf("CHC Software")}}>=0,2,0)
+ IF({{issue.Solution Change Type.join("_").indexOf("On-Prem Infra")}}>=0,3,0)
+ IF({{issue.Solution Change Type.join("_").indexOf("Content Changes (outside software code)")}}>=0,1,0)
{{/}}
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.
August 25, 2021

Yup, that second way should work also.  In that approach, you can set the Story Points in one step and no re-fetch calls are needed.

Make sure you test the edge cases of no values and all values selected to confirm you get what you wanted.

__Bill

Suggest an answer

Log in or Sign up to answer