Send custom email on selecting Group value in custom Group Picker on Transition screen in Jira DC

Digvijay Singh Gehlot
Contributor
July 4, 2024

Hi Community,

I have added a custom Group Picker field on a transition screen.

I want to send a custom email after currentUser selects the value in custom Group Picker field and then clicks on Transition Name button on Transition screen.

And is there a way to send individual emails to each user (present in Group) after performing the above action? 

How can we configure this in JIRA Data-center by using either scriptrunner, post-functions, JMWE app, or JIRA automation?

As I am new to customizations in JIRA, it would be a great learning for me.

Thank you.

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Reshma Begum {Appfire}
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.
July 5, 2024

Hi @Digvijay Singh Gehlot ,

Using JMWE Email Issue Post Function, you can achieve your requirement.

Configure the Email Issue Post function as shown below:

2024-07-05_17-27-33.png2024-07-05_17-28-34.png

Add the below groovy script in the Email addresses field 

<% String input = issue.get("customfield_12200").name
String result = input.replaceAll("[\\[\\]]", "") %>
${ComponentAccessor.groupManager.getUserNamesInGroup(result).join(",")}

The above script gets the email addresses of all users within the group selected in the field. 

Add the conditional execution as shown below to send the email only when the group picker field has some value. 

!!issue.get("customfield_12200")

2024-07-05_17-30-28.png

customfield_12200 is the group picker field. Please modify the ID as per your instance.

Hope this helps!

BTW, I am Reshma from Appfire, a vendor of JMWE.

Thanks,

Reshma

Digvijay Singh Gehlot
Contributor
July 5, 2024

Hi @Reshma Begum {Appfire} 

Thank you for your message. 

I am successfully able to configure the Email Issue Post Function (JMWE app) at my end as you mentioned.

But I am not able to see email coming to user's inbox.

I am passing the same code in Email Address section (by replacing the cf ID) and it is not giving me any error logs after selecting a value in custom Group Picker (single group) field on Transition screen. Everything looks fine and Green with the Logs. But user is not receiving the email.

However, I tried by selecting "Specific User" and the email is received successfully. 

Is there a way we can use "Users from script" or "Users in field(s)" in case of custom Group Picker (single group) field?

Also in HTML Body section, I am adding:

${issue.get("<custom_group_picker_name>").name}

- The output is showing Group Name in brackets i.e. [Test Group] : how can we remove [ ] brackets from the Group Name?

I also want to display user names (present in Test Group) in Email content, so I am adding:

${ComponentAccessor.groupManager.getUserNamesInGroup(issue.get("customfield_XXXXX").name)}

- The output is showing [SSO ID] instead of Full User Name(s) : how can we show full user name - present in Test Group?

Please kindly assist further and let me know if you need any additional details.

Thank you.

Reshma Begum {Appfire}
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.
July 8, 2024

Hi @Digvijay Singh Gehlot ,

For the HTML Body section, please modify the script as below:

${ issue.get("customfield_xxx").name.toString().replaceAll("\\[","").replaceAll("\\]", "")}

 This will display the group name without brackets. 

Please try the below script in the users from script section:

def originalString = issue.get("customfield_xxxx").name.toString()
def cleanedString = originalString.replaceAll("\\[","").replaceAll("\\]", "")

 ComponentAccessor.groupManager.getUserNamesInGroup(cleanedString).join(",")

 Please note that we have created a support request SUPPORT-184226  in our portal. We’d like you to sign up for the portal and let us know your username so that we can mark your ID as the reporter so you will be able to access the ticket.
Please find the below link to sign up on the portal: link
We are looking forward to hearing from you!

Thanks,

Reshma

Digvijay Singh Gehlot
Contributor
July 10, 2024

Hi @Reshma Begum {Appfire} 

Thank you so much, it helped me to learn more about Email Issue - Post Function (using JMWE app).

I am able to achieve my use case by following your suggested script changes and can send emails to individual users when a value is selected in custom Group Picker field.

In HTML Body section, I am also able to display User's Full Name instead of their SSO IDs (present in Group) by passing this:

${ComponentAccessor.groupManager.getUsersInGroup(issue.get("customfield_xxxxx)).displayName.join(",")}

Thank you again for creating a Support request on my behalf in your portal. I have signed up for Appfire portal with this username: Digvijay Singh Gehlot and please let me know once my ID is added to that request.

Best regards,

Digvijay

Like Reshma Begum {Appfire} likes this
OMAR MOHAMED AHMED MOHAMED FATHY
Contributor
March 18, 2025

thank you life saver <3 

0 votes
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 4, 2024

Hi @Digvijay Singh Gehlot 

this should be possible with scriptrunner and a workflow post-function.

You creste a custom script post function.

Within the script you can grab the issue and the customfieldValue of that userGroup picker, collect all users of that group as a list lf users, iterate over this list and send an email to each user.

Best
Stefan

Digvijay Singh Gehlot
Contributor
July 5, 2024

Hi @Stefan Salzl 

Thank you for your email.

May you share the custom script which I can use in scriptrunner post function as an example?

I will thorough go through that and modify it as per my requirements.

Thanks.

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 6, 2024

Hi @Digvijay Singh Gehlot 

unfortunately I don´t have a DC instance on my site. I did a lot of scriptrunner coding at customer site so I know it´s possible with only a script. I can´t use there environment for community use cases but I´ll have a look next week if I can find something similiar in my scripts there.

Furthermore the community is a place to show possibilities and not to get a built custom solution (which some of us do for a living as freelance consultants - no offense).

I would rather suggest to get familiar with scriptrunner and it´s classes and functionalities:

https://docs.adaptavist.com/sr4js/latest/get-started

https://docs.adaptavist.com/sr4js/latest/training

 

Best
Stefan

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 6, 2024

@Digvijay Singh Gehlot 

try the following as a starting point:

 

def issueManager = ComponentAccessor.getComponent(IssueManager)

def cfManager = ComponentAccessor.getComponent(CustomFieldManager)

def userManager = ComponentAccessor.getComponent(UserManager)

def groupManager = ComponentAccessor.getComponent(GroupManager)





def groupField = cfManager.getCustomFieldObject("customfield_12306")

log.warn(issue.getCustomFieldValue(groupField).name)

def benutzerGroups = issue.getCustomFieldValue(groupField)

benutzerGroups.each {group ->

    log.warn "Group name: " + group.name

    groupManager.getUsersInGroup(group).each { user ->

        log.warn user.displayName + ", " + user.emailAddress

    }

   

 }

 

As you figure out the steps of the script you could then use the mail address within the each iterator to send an email to the user.

 

Best
Stefan

Digvijay Singh Gehlot
Contributor
July 8, 2024

Hi @Stefan Salzl 

Thank you for sharing the code reference.

I implemented the same code concept in my custom script - scriptrunner post function and imported the necessary classes as below:

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.component.ComponentAccessor

def
issueManager = ComponentAccessor.getComponent(IssueManager)
def cfManager = ComponentAccessor.getComponent(CustomFieldManager)
def userManager = ComponentAccessor.getComponent(UserManager)
def groupManager = ComponentAccessor.getComponent(GroupManager)
def groupField = cfManager.getCustomFieldObject("customfield_12306")

log.warn(issue.getCustomFieldValue(groupField).name)

def benutzerGroups = issue.getCustomFieldValue(groupField)

benutzerGroups.each {group ->

    log.warn "Group name: " + group.name

    groupManager.getUsersInGroup(group).each { user ->

        log.warn user.displayName + ", " + user.emailAddress

    }
 }

However, I am unable to execute the code and getting the below error messages:

1) group.name : [Static type checking] - No such property: name for class: java.lang.Object

2) groupManager.getUsersInGroup(group).each : [Static type checking] - Cannot find matching method com.atlassian.jira.security.groups.GroupManager#getUsersInGroup(java.lang.Object). Please check if the declared type is correct and if the method exists.

3) user.displayName : [Static type checking] - No such property: displayName for class: java.lang.Object

4) user.emailAddress : [Static type checking] - No such property: emailAddress for class: java.lang.Object

Please guide where I am making the mistake here.

Thanks.

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 8, 2024

You have to replace the customfield_id with the id of your group picker field.

In general:
Please get familiar with scripting and scriptrunner. It‘s not a copy paste job with scripts and I can‘t guide you througj your situation without seeing your system/entities. 

scriptrunner needs (at least some basic) scripting skills and understanding what the lines are about.

Please read the links shared in my former post and get familiar with scriptrunner rather than asking for a ready to use solution.

Best
Stefan

TAGS
AUG Leaders

Atlassian Community Events