Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Post function groovy: Send mail whenever user picker selected for the custom field

Imdad KP
Contributor
April 1, 2019

I want to trigger emails and assign the issue to same as user picker value. How can I achieve that?

For an example: If I select abc@gmail.com for cf TVT in create screen it should assign an issue to the user and send mail notification.

tvt.JPG

1 answer

1 accepted

0 votes
Answer accepted
Prakhar Srivastav {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.
April 2, 2019

@Imdad KP 

You can create a Post Function which will copy the field TVT to assignee field in JIRA. You can assign this Post Function on Create Issue Transition.

JIRA Notification Scheme will take care of sending the mail to assignee unless it is customised otherwise

For creating the Post Function there are many add-ons you can use (based on if you have them in your system )

Some examples are :

Scriptrunner

Update on Transition

JSU

JIRA Misc Workflows

 

You may explore them

 

Regards

Prakhar

Imdad KP
Contributor
April 2, 2019

Hi @Prakhar Srivastav {Appfire} ,

 

Thanks for that, is it possible to provide you with any sample groovy script for the same. I am using Scriptrunner plugin for this process.

 

Thanks,

Imdad KP

Prakhar Srivastav {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.
April 2, 2019

Hi @Imdad KP 

You can find many articles for this. For example you can refer this link :

https://community.atlassian.com/t5/Jira-questions/Updating-assignee-via-scriptrunner/qaq-p/637155

Regards

Prakhar

Imdad KP
Contributor
April 4, 2019

Hi Prakhar,

 

I am writing this the first time. Could you please help me to understand the issue here.

 

package com.imdad.scripts

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserUtils
import org.apache.log4j.Level
import org.apache.log4j.Logger

def log = Logger.getLogger("com.imdad.scripts")
log.setLevel(Level.INFO)

def approversFiledMapping = [
"BVT" : "customfield_11120", // Assignee user picker field id
"IVT" : "customfield_11127",
"FVT" : "customfield_11128",
"SVT" : "customfield_11129",
"PVT" : "customfield_11130",
"AVT" : "customfield_11131",
"GVT" : "customfield_11132",
"TVT" : "customfield_11133"
]

 


//current issue object
Issue issueContext = issue
log.debug("current issue key - ${issue.key}")
def issueFactory = ComponentAccessor.getIssueFactory();
def issueManager = ComponentAccessor.getIssueManager();
def authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
def customfieldManager = ComponentAccessor.getCustomFieldManager()

CustomField cfTestingType = customfieldManager.getCustomFieldObject("customfield_11120") //Testing Type field ID
Collection<Option> cfTestingTypeValues = (Collection<Option>)issue.getCustomFieldValue(cfTestingType)
log.info("testing types ${cfTestingTypeValues}")
if(cfTestingTypeValues && !cfTestingTypeValues.empty){
for(Option option: cfTestingTypeValues){
log.info("Testing Type value ${option.value}")
// create new issue from factory
def issueObject = issueFactory.getIssue();
//set values
issueObject.setProjectObject(issue.getProjectObject()); //setting target project
issueObject.setIssueTypeId("10502"); //setting target issue type
issueObject.setSummary(issue.getSummary()); //Copying summary
issueObject.setDescription(issue.getDescription()); //copying description
issueObject.setReporter(issue.getReporter()); //copying reporter

CustomField cf = customfieldManager.getCustomFieldObject(approversFiledMapping.get(option.getValue()))
if(cf){
ApplicationUser user = (ApplicationUser)issue.getCustomFieldValue (cf)
if(user){
log.info("Approver ${user.name}")
issueObject.setAssignee (user) //set Assignee
}

}

//copy customfield values
CustomField cfROO = customfieldManager.getCustomFieldObject("customfield_11100") //Release Overview
if(cfROO){
issueObject.setCustomFieldValue(cfROO, issue.getCustomFieldValue(cfROO))
}else {
log.debug("Release Overview customfield not found....")
}

CustomField cfSAL = customfieldManager.getCustomFieldObject("customfield_11101") //Scope
if(cfSAL){
issueObject.setCustomFieldValue(cfSAL, issue.getCustomFieldValue(cfSAL))
}else {
log.debug("Scope customfield not found....")
}

CustomField cfOI = customfieldManager.getCustomFieldObject("customfield_11102") //Offering Information
if(cfOI){
issueObject.setCustomFieldValue(cfOI, issue.getCustomFieldValue(cfOI))
}else {
log.debug("Offering Information customfield not found....")
}

//create actual issue
def targetIssue = issueManager.createIssueObject(authenticationContext.getLoggedInUser(), issueObject)
log.info("Target Issue Key - ${targetIssue.key}")
}
}

 

What I am trying to achieve here, whenever I choose any user value in BVT or IVT etc.. JIRA should create that many number of issues and the same user will get assigned the ticket.

BVT.JPG

Suggest an answer

Log in or Sign up to answer