Brew Up Better Jira Automations: Advanced Smart Value Tips, Conditional Smart Values and Loops

Brew Up Better Jira Automations: Advanced Smart Value Tips, Conditional Smart Values and Loops

Jira Automation is a powerful tool that can streamline your workflow and boost productivity.

However, to truly harness its potential, you need to master the art of smart values. In this article, we'll delve into advanced smart value techniques, including conditionals and loops, to help you create more sophisticated and efficient automations. I will also go through a real life case that I encountered recently where I wanted to only surface up the last external comment and the last internal comment only.

These are lessor known features which are not documented well, I have often tried to look for ways to attain complex actions which would be impossible without Smart Value conditionals and Smart Value loops. In conjunction with webhooks, these can be used to filter responses also, granting increased flexibility in all rules.

The only documentation I found around this from Atlassian is the Automation Smart Values - Conditional Logic.

I will be referencing the official Atlassian documentation in this article also.

Understanding Smart Value Conditionals

Conditional smart values allow you to create dynamic and flexible actions inside automation based on specific criteria. By using functions like if, equals, exists, and, and or, you can control the behavior of your automation rules. ?

Now we will examine the core functions that can be used to filter smart values, these can be combined with smart value loops also as you will see in the capstone Case Study.

These smart values only work with text.

if

Syntax

{{if(smartValue)}}         

returns true or null.

{{if(smartValue)}}Hello{{/}}         

returns Hello or null. If the smart value is null, Hello will be printed.

{{if(smartValue, “Hello”)}}         

returns Hello or null. If the smart value is null, Hello will be printed.

{{if(smartValue, "value if true", "value if false")}}         

allows you to add a specific value when the condition is not matched.

Example

Let’s say you have a list of issues (perhaps from a Lookup issues action), and you want to add a comment to any that have linked issues. You could use the?Add comment?action with the following input to add a comment to each issue that has at least one linked issue:

{{#if(not(issue.issuelinks.isEmpty))}}
This bug has {{issue.issuelinks.size}} related tickets
{{/}}        


equals

Syntax

{{equals("string1", "string2")}}         

returns true if the two inputs are equal, and false if they aren’t.

{{equals(smartValue1, smartValue2)}}         

returns true if the two inputs are equal, and false if they aren’t.

Example

Let's say you have a process in your team, whereby the assignee and the reporter must be different team members for auditing purposes.?You could use the?Add comment?action with the?following input to add a comment to each issue to remind your team that this is the case:

{{#if(equals(issue.assignee, issue.reporter))}}
Assign this issue to someone else so they can review.
{{/}}        

exists

Syntax

{{exists(smartValue)}}         

returns true or null

{{exists("string")}}         

returns true or null

Example

Let's say you have a custom field on your issues called Designer.?You could use any action that prints text (such as Add comment,?or Send Slack message) to inform people with the following input:

{{#if(exists(issue.designer))}} 
The designer for this issue is {{issue.designer.displayName}} 
{{/}}        

In this case, if the field?Designer has a value, your output would be?The designer for this issue is?(designer's name).?If the Designer field is empty, no comment would be added.


not

Syntax

{{not(smartValue)}}         

returns true or false

Examples

Let’s say you have a list of issues (perhaps from a?Lookup issues?action), and you want to add a comment to any that have linked issues. You could use the?Add comment?action with the following input to add a comment to each issue that has at least one linked issue:

{{#if(not(issue.issuelinks.isEmpty))}}
This bug has {{issue.issuelinks.size}} related tickets
{{/}}        

Here, the?not smart value checks to see if an issue has at least one related issue. For example,?if an issue has 4 related issues, then the comment?This bug has 4 related tickets?would be added.

and

Syntax

{{and(smartValue1, smartvalue2)}} returns true or false

Examples

Let's say you have a list of issues that have a?Votes custom field. You could use the?Add comment?action to add a comment to all issues that have greater than 100 votes, and less than 150 votes:

{{#if(and(issue.Votes.gt(100),issue.Votes.lt(150)))}}
Moderately Popular issue
{{/}}        

or

Syntax

{{or(smartValue1, smartvalue2)}}         

returns true or false

Examples

Let's say you've got a project that customers use to report bugs, and your issues have a?Votes?custom field. You could gather a list of issues using the?Lookup issues?action, and then?use the?Add comment?action to add a comment to all issues that have either more than 100 votes, or more than 20 comments:

{{#if(or(issue.Votes.gt(100),issue.comments.gt(20)))}}
Heavily requested issue
{{/}}        

Here, the?if?smart value checks for more than 100 votes or more than 20 comments, and adds the comment?Heavily requested issue.

By combining these functions, you can create complex conditional logic to tailor your automation rules to specific scenarios. For instance, you could trigger a notification only if an issue is critical and has a specific custom field value.


Case Study: Retrieving the Last Internal/External Comment from a Jira Issue

Let's explore a practical example of using advanced smart values to retrieve the last internal or external comment from a Jira issue. This information can be valuable for various automation scenarios, such as sending notifications, comparing the new comment for duplicates, sending comment information to customers/agents or simply updating custom fields.

While Jira does provide a direct function smart value to get the last comment, we can't easily retrieve the last internal or external comment.

{{issue.comments.last.body}}        

This was a real case study that was solutioned, we will create two variables to retrieve the last internal or external comment.

Variable one

This variable is:

  • Collecting all the comments on the issue
  • Looping through them
  • Filtering them with the {{#if(internal)}}
  • Surfacing all the internal comments

Note: I am also indicating the start of a comment with the - character, this will be useful for the refinement in variable two.

{{#issue.comments}} {{#if(internal)}}  - {{body}}  {{/}} {{/}}        

Output:

Variable two

This variable is:

  • Splitting "Variable one" by the "-" character, comments are listed from from first posted to last
  • Surfacing the last segment of the split comments, ultimately retrieving the last Internal comment

Output:

By following these steps and combining them with appropriate smart value functions, you can successfully extract the last Internal/External comment from a Jira issue and use it in your automations.


Note: If you want to retrieve the last External comment, all you need to do is change "Variable one" to:

{{#issue.comments}} {{#if(not(internal))}}  - {{body}}  {{/}} {{/}}        

This is just adding the not keyword so it will accept the False response and return External comments.

Conclusion

Mastering advanced smart value techniques, such as conditionals and loops, is essential for creating powerful and efficient Jira automations. By understanding how to use these features effectively, you can automate complex workflows, improve team productivity, and enhance overall issue management.

Remember to experiment with different combinations of smart values and test your automations thoroughly to ensure they behave as expected. With practice and creativity, you can unlock the full potential of Jira Automation and streamline your work processes.


Sponsored by Elegance Group - Atlassian Platinum Partner

Proudly sponsored by Elegance Group, a distinguished Atlassian partner recognized globally and awarded Partner of the Year in 2022 and still conducting consistent elegant solutions.

For expert advice on Licensing or Services from an acclaimed Atlassian Partner, reach out to Elegance Group.

Book a meeting with us to enhance your business with our unparalleled Atlassian solutions.



要查看或添加评论,请登录

Brandon Davies的更多文章

社区洞察

其他会员也浏览了