Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,847
Community Members
 
Community Events
168
Community Groups

Automation for Jira : How get the approver value Display name?

Edited

Hello! 

i'm trying to generate a custom Approval email, i tried using the Customer Notification but i have custom field from Insight what i need to add. Seems not possible using this function and i'm trying with Automation for Jira. 

I making the email template and i don't find the good smart value for the Approver(s). I don't find the response here : https://support.atlassian.com/jira-software-cloud/docs/what-are-smart-values/

 

I tried 

{{#issue.Approver}}

{{issue.Approver}}

Is it possible to get back this value? 

Other question: Is it possible to get back the value of an Insight custom field? 

Additionally, can we have the approval button to a Jira automation ?

 

Thank you !

4 answers

2 accepted

1 vote
Answer accepted

With Automation for Jira, is there a way to add an Approve/Decline button to a custom email notification?  

Hello,

i don't found that  

Like # people like this

Have you found a solution to this problem? I'm looking for options myself.

1 vote
Answer accepted

Hello,

 

to display the approver, i found : {{issue.Approvers.displayName}}

Use the following:

 

{{issue.customfield_10026.approvers.get(0).approver.get(0).displayName} Should pull the first alphabetical name of the approvers list. then your next entry would be {{issue.customfield_10026.approvers.get(0).approver.get(0).displayName} and incrementing the number for each approver.

 

In your case replace customfield_10026 with the customfield number that Jira created for the Approvals field.

 

{{issue.{replace with Custom Field number for the field Approvals in your instance}.approvers.get(0).approver.get(0).displayName}

 

If you want a incremented list in a new field and populate it would look something like this.

{{issue.customfield_10026.approvers.get(0).approver.get(0).displayName}} - {{issue.customfield_10026.approvers.get(0).approverDecision.get(0)}}\\{{issue.customfield_10026.approvers.get(0).approver.get(1).displayName}} - {{issue.customfield_10026.approvers.get(0).approverDecision.get(1)}}\\{{issue.customfield_10026.approvers.get(0).approver.get(2).displayName}} - {{issue.customfield_10026.approvers.get(0).approverDecision.get(2)}}

 

Alex Smith - Approved

Doug Jones - Pending

Tyler Johnson - Pending

 

Hopefully the first part will help you though if you only need emails on pending.

The above is working for me, but I want the email to address only the individual recipient of the email, not everyone on the approvers list. {{issue.approvers.displayName}} shows a comma separated list of approvers. Is there a way to iterate on this, so that the email goes to all pending approvers, but the body references only that specific recipient?

 

For instance, approvers list contains: Jane Doe, John Smith,

I want the email to say:

 

Dear {{issue.approvers.displayName.SOMEFUNCTION}},

This is my message.

 

So that Jane's says

 

Dear Jane Doe,

This is my message.

 

and John's says

 

Dear John Smith,

This is my message.

 

But instead, I'm getting

 

Dear Jane Doe, John Smith,

This is my message.

I have the same issue, how to get the single name?

 {{issue.approvers.get(0).displayName}} Should pull the first alphabetical name of the approvers list. then your next entry would be {{issue.approvers.get(1).displayName}} and incrementing the number for each approver.

{{issue.approvers.get(0).displayName}} - {{issue.customfield_10026.approvers.get(0).approverDecision.get(0)}}\\{{issue.approvers.get(1).displayName}} - {{issue.customfield_10026.approvers.get(0).approverDecision.get(1)}}\\{{issue.approvers.get(2).displayName}} - {{issue.customfield_10026.approvers.get(0).approverDecision.get(2)}}

There is a caveat to this though as I found out. The approvers values are pulled off a alphabetical list.  When Jira generates the approvers list that shows pending or approved, If someone approves it could send to the wrong person. What i am observing is that when someone approves, their name is resorted alphabetically with all those that approved listed first and then those that are still pending approval listed last. If you try to do a incremental positional return of the list of approvers values it then is out of order.

 

I actually then utilized the automation tools to trigger a update of a field that displays these status

 

Alex Smith - Approved

Doug Jones - Pending

Tyler Johnson- Pending

 

When Tyler Johnson approves I find that because of how the approvers are listed it displays this.

Alex Smith - Approved

Doug Jones - Approved

Tyler Johnson- Pending

 

I think Jira reorders the list of names so that all approvers are listed first. The get tells it to grab the first alphabetical name and then the second, and then the third.

Hopefully the first part will help you though if you only need emails on pending.

 

Like # people like this

@Alex Sprague - thanks, your contribution helped me with what I wanted to do. 

We allow 2 or more approvers to be added, and I wanted to send out a notification/comment that shows who the remaining pending approvers are.

I've found nothing yet that would trigger an autoamtion/webhook when an approval is added, but as a workaround, I've created a scheduled JQL Automation rule (all issues pending approval).

The following smart value formatting shows me the list of pending approvers for each of the approvers.

{{#issue.customfield_10027.last.approvers}}
{{approver.displayName}} - {{approverDecision}}
{{/}}

Output e.g. :
User 1 - approved
User 2 - pending

Like # people like this

After digging into this a bit more I realized there is a problem.

You have "last.approvers" which doesn't actually get the latest approver set, but rather, the last in the list, which is the first.  This isn't a problem if there is only one round of approval, but if there are multiple, you will find that the last.approvers syntax provides the same output every time  once you get beyond the first round of approvals.

To fix this use "first.approvers" instead.

{{#issue.customfield_10027.first.approvers}}
{{approver.displayName}} - {{approverDecision}}
{{/}}

The reason for this is the way the API call gets the JSON structured data.  Last is referring to the ordered list of Approval Sets, which since they increment upwards means Last in the list of Approvals which is the first chronological Approval.  First in the list would actually be the latest.

Thanks for the help on this.

@Cronje van Heerden This was exactly how i set it up in order to display pending approvals . I had to schedule a 5 minute timed update that pulled the list of approvers and their statuses. For anyone else who stumbles on this post I want to point out that I had created a custom field called Approvers Cnt that i populated using the smartvalue {{issue.customfield_10003.size}}.  Follow this up with doing a if match conditional statement. The Approver Cnt determines which approver status statement to use. below is if cnt is 1.

Approvers automation.png

 

If count is 2 use this:

{{issue.customfield_10026.approvers.get(0).approver.get(0).displayName}} - {{issue.customfield_10026.approvers.get(0).approverDecision.get(0)}}\\{{issue.customfield_10026.approvers.get(0).approver.get(1).displayName}} - {{issue.customfield_10026.approvers.get(0).approverDecision.get(1)}}\\

 

Keep incrementing to whatever max approver field size you anticipate. I stopped at a Count of 10.

Like # people like this

Very clever .. I'll try that as well ... 

I'd just be very cautious about the overall performance impact these scheduled automations might have. We have some project that have added 100k new issues in the last year, and if I had to run this automation in a project with so many issues I'd very very surprised if something doesn't break.

Has anyone else had this problem with the answer given here? I've also tried the {{issue.approvers}} solution with the same result (no such property).

I've double checked that that is the name of my instance's "Approvals" field. What am I missing?

My full script is

```

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueByCurrentKey("my issue here")

log.warn(issue.customfield_10700.approvers.get(0).approver.get(0).displayName)
```
and a screenshot of the error is below

Web capture_8-6-2022_16645_jira.sdl.usu.edu.jpeg

It looks like the code that you are using is for Jira Server and not Jira cloud. The above solution only works for Jira Cloud.

Ah that would explain it, thank you!

For anyone that finds this looking for the solution on Jira Server, we ended up having to query our actual database, since everything else we found removes approvers if the names change in the field approvers are pulled from. So the only reliable record of who had approved or denied things in the past is held in the database, as far as I could find!

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events