Hello All,
How to send an email notification to a group on custom field value selection when issue is created?
Example: We have a custom field called Product(single select) and it has options Part1, Part2, Part3 and we have 3 groups Group 1, Group 2, Group 3. If user selects option Part1 it has to send notification the users in the Group 1 same as Part2 is selected it has to send notifications to Group 2.
I have added "Fire a Issue Created event(script runner)" on custom field value selection in post function as below but how to add a condition to send email to particular group on custom field value selection?
cfValues['Product']?.value == 'Part1'
I am new to scripting. Can any one please help me.
Thanks in Advance,
Mani
Hi mani@123 ,
My advice would be the following :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
int selectListId = 13500
def selectList = customFieldManager.getCustomFieldObject(selectListId)
def selectListValue = issue.getCustomFieldValue(selectList)
def groups = ["Part1": "Group1",
"Part2": "Group2",
"Part3": "Group3"]
def groupToSendMail = ComponentAccessor.getUserUtil().getGroup(groups[selectListValue?.getValue()])
int groupCfId = 13900
def groupCf = customFieldManager.getCustomFieldObject(groupCfId)
def groupCfValue = issue.getCustomFieldValue(groupCf)
if (groupToSendMail != groupCfValue){
groupCf.updateValue(null, issue, new ModifiedValue(groupCfValue, [groupToSendMail]), new DefaultIssueChangeHolder())
}
Make sure to replace the ids. If a value is not mapped, the group picker will not have any value.
Antoine
Is it possible to send notification to single user instead of group on custom field value selection?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi mani@123 ,
Do not worry about the static errors, they will resolve at execution time.
Yes this is possible to send a mail to a single user, change the notification scheme accordingly, the logic is the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Below error in the log file:
2019-07-17 19:22:00,638 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-07-17 19:22:00,640 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: FLW02-28637, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script32 at Script32.run(Script32.groovy
I am new to scripts. Please help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I forgot to add the declaration of the customFieldManager... use this :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def customFieldManager = ComponentAccessor.getCustomFieldManager()
int selectListId = 13500
def selectList = customFieldManager.getCustomFieldObject(selectListId)
def selectListValue = issue.getCustomFieldValue(selectList)
def groups = ["Part1": "Group1",
"Part2": "Group2",
"Part3": "Group3"]
def groupToSendMail = ComponentAccessor.getUserUtil().getGroup(groups[selectListValue?.getValue()])
int groupCfId = 13900
def groupCf = customFieldManager.getCustomFieldObject(groupCfId)
def groupCfValue = issue.getCustomFieldValue(groupCf)
if (groupToSendMail != groupCfValue){
groupCf.updateValue(null, issue, new ModifiedValue(groupCfValue, [groupToSendMail]), new DefaultIssueChangeHolder())
}
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Antonie,
Created different workflows for each issue type and added above script in the create transition for story workflow. In the notification scheme mapped Group field to the "Issue Created" event. But it is sending notifications on creation of all issue types in the project
There is no error in the logs.
Thanks in Advance,
Manikanta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi mani@123 ,
If you want to send notifications for only one issue type, you should use a custom event. i.e. :
That way notifications will only be sent for this event.
Let me know if that helped.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.