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

How to define action for empty smart value?

Jenni February 9, 2022

Hello,

I have a following script that lists issues in Slack message depending on issue priority:

*{{issue.summary}}* has been completed *({{Perforce Branch.value}} {{Platform Options.value}} {{Build exe.value}}*).
*CL:* {{Revision}}
*Link:* <{{issue.url}}|{{issue.key}}>
*Tester:* {{initiator.displayName}}

*Results:*

:blocker: *Blocker*
{{#issue.issuelinks.outwardIssue}}
{{#if(equals(priority.name, "Blocker"))}}
* <{{url}}|{{key}}> - {{summary}}
{{/}}{{/}}

:bangbang: *Critical*
{{#issue.issuelinks.outwardIssue}}
{{#if(equals(priority.name, "Critical"))}}
* <{{url}}|{{key}}> - {{summary}}
{{/}}{{/}}

:large_red_square: *Major*
{{#issue.issuelinks.outwardIssue}}
{{#if(equals(priority.name, "Major"))}}
* <{{url}}|{{key}}> - {{summary}}
{{/}}{{/}}

:large_green_circle: *Normal*
{{#issue.issuelinks.outwardIssue}}
{{#if(equals(priority.name, "Normal"))}}
* <{{url}}|{{key}}> - {{summary}}
{{/}}{{/}}

:large_blue_circle: *Minor*
{{#issue.issuelinks.outwardIssue}}
{{#if(equals(priority.name, "Minor"))}}
* <{{url}}|{{key}}> - {{summary}}
{{/}}{{/}}

 However, I'm not sure how to add to the script when there is, say, no Minor issues? If there is nothing to print, currently there's just empty space after the heading - but I'd like it to say something like ":tada: No new Minor issues found!" Not just sure what IF or NOT condition I should be referring to?

Pinging @Mykenna Cepek as you've provided great answers before! :)

1 answer

1 accepted

1 vote
Answer accepted
Mykenna Cepek
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2022

Wow, my first shout-out right in the OP. I'm humbled, @Jenni !

So, one option is to use nested #if statements to suppress an entire section:

{{#if(equals(0,0))}} {{#if(equals(1,1))}} hello {{/}} {{/}}

But that's starting to get excessive and hard to read.

Something else to consider would be to pull out most of the #if logic into conditionals in the rule before the Slack action, and build variables for the output. Then when creating the slack message:

{{#if(not(myvar1.equals("x")))}}
{{myvar1}}
{{myvar2}}
{{/}}

or whatever.

Note that I've not had good success with defining blank variables in automation. That's why my example above checks against "x". There may also be issues with newline in variables.

So the pseudocode for one section might be like:

  • action: set variable(s) to "x"
  • conditional: if priority.name = "Major" then set variable(s) to real values

I hope that makes sense.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events