Is it possible to create a new ticket whenever the custom field gets updated, using Scriptrunner

Sahish April 21, 2022

Hey Guys,

Hope everyone are doing great.

I have two statuses like In Analysis and Implementation. Between this we have Implement transition screen. Whenever I am changing the status from Analysis to Implement, I will get one popup screen which has Multiple Variants and Affected Variants (dropdown list like say A, B, C, D, E, F etc.,) Custom fields. If I select Affected variants are some abc, efg , so immediately separate two new issue tickets will be created for these affected variants (used post functions to create a ticket over here) and the issue will be in Implementation status.  

So now during this status, I found that other affected variants Like klm, xyz also affecting. I updated the original ticket with these variants from the edit option on the screen. So now the total variants are abc,efg,klm,xyz. Now I need to get another separate two new issue tickets for the affected variants klm and xyz.

One more thing, If I update the custom field "Affected Variants " in project called "ABC", the issue ticket should create in project called say "XYZ".

This is my requirement.

And after creation of issue, is it possible to get some dialog box on screen with the information "New issue ticket created". ?

We already have two post functions in the workflow for creating one new issue in two different transitions:

This post function in "Implement" transition.

yo 1.PNG

This post function in "Create new issue" transition. 

yo.PNG

 

Is it possible ? If yes please advise me how to proceed further.

For the below code I am currently testing in the Listeners for issue updated event.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version

//Take issue from source project
def issue = event.issue as MutableIssue

def summary = 'This is new issue'
def description = 'This is auto create issue'
def issueFactory = ComponentAccessor.issueFactory
def issueManager = ComponentAccessor.issueManager
def projectManager = ComponentAccessor.projectManager
def customFieldManager = ComponentAccessor.customFieldManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def sampleVersions = customFieldManager.getCustomFieldObjectsByName('Affected Variants for New Issue').first()
def sampleVersionsValue = issue.getCustomFieldValue(sampleVersions) as ArrayList<Version>

//Configure Target Project
def project = projectManager.getProjectByCurrentKey('SBSV')

def issueObject = issueFactory.issue

if (sampleVersionsValue.size() > 0) {
issueObject.setProjectObject(project)
issueObject.setIssueType(issue.issueType)
issueObject.setSummary(summary)
issueObject.setDescription(description)
issueObject.setCustomFieldValue(sampleVersions, issue.getCustomFieldValue(sampleVersions) as ArrayList<Version>)
issueObject.setReporter(loggedInUser)
issueManager.createIssueObject(loggedInUser, issueObject)
issueObject.setPriority(issue.priority)
issueManager.updateIssue(loggedInUser,issueObject, EventDispatchOption.DO_NOT_DISPATCH,false)
}

Thanks in advance,

 

1 answer

0 votes
Nic Brough -Adaptavist-
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 21, 2022

It's better to use the issueService to create issues - there's an example at https://library.adaptavist.com/entity/create-a-sub-task-and-link-to-parent-issue-in-jira (just drop the bit about setting the parent issue)

Suggest an answer

Log in or Sign up to answer