Jira automation - create a Slack message if fields have changed

Mark Haller
Contributor
December 2, 2023

What I want - when one of four fields change on any ticket by a member of a role, I want to be sent one Slack message showing the changes.   Sounds super simple, right?

So I've got "When: Value Changes for" and selected my four fields.

What I would like to do next is "Send Slack Message" action and build the string using inline if.  But I can't for the life of me figure out the format!

I've got -

Key fields on ticket <a href="{{issue.url}}">{{issue.key}} - {{issue.summary}}</a> have been changed by {{initiator.displayName}}, as follows:


{{if(equals({{changelog.T-shirt Size.fromString}}, {{changelog.T-shirt Size.toString}}))}}
T-shirt size has changed from {{changelog.T-shirt Size.fromString}} to {{changelog.T-shirt Size.toString}}
{{/}}

And just repeat the if(equals) for each of the four fields.  I obviously need to negate the statement too with a not() somewhere!

I've tried putting the fromString in braces, out of braces, you name it - and most times receive mismatched start/end tags.

Can someone help please?

1 answer

1 accepted

4 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.
December 2, 2023

Hi @Mark Haller 

Here is the documentation on conditional, smart value expressions to get you started: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/

Another key thing is the smart values...they are name, spacing, and case-sensitive.  And, a field's smart value may not match the display name on the issue views.  And so I recommend pausing and using this how-to article to confirm the smart values for your fields. https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

Essentially the steps are: find an example issue with your field(s), call a REST API function using a browser, search on the page for your field (e.g., with CTRL-F), and if you find your field, the correct smart value and custom field id will be shown.  If the field is not shown, it is either not supported by rules or not configured for your issue type. 

With all that out of the way...you seem to be trying to show some text when a field has changed.  Here is one way to do that, simply testing for the presence of a changelog entry for a field:

{{#if(exists(changelog.summary))}}The summary has changed from "{{#changelog.summary}}{{fromString}}{{/}}" to "{{#changelog.summary}}{{toString}}{{/}}"{{/}}

When a field has not changed, there is no changelog entry, and if that is not checked first, parts of an expression can collapse to null...resulting in unusual and confusing errors in the audit log.

Kind regards,
Bill

Mark Haller
Contributor
December 2, 2023

Hey @Bill Sheboy I had seen you reply to others regarding automation questions and was hoping you'd see my question and wondered what timezone you were in!

I just output the whole "changelog" and can see what the field names are - which is brilliant.

And then took your if(exists( command, verbatim and it's work absolutely perfectly.

Thank you so much - this is SO useful! :-)

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.
December 2, 2023

Awesome; I am glad to learn that helped!

I like that that technique of outputting the whole changelog, yet it may not always work.  When an object is just written to the log / used, sometimes it only returns the default attribute.  For example, writing {{issue}} normally only returns the key.  As rule behaviors like that are not documented, who knows if they will change in the future  :^)

Suggest an answer

Log in or Sign up to answer