Forums

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

Update linked issue through Groovy Script using script runner

Vaibhav kamble
Contributor
January 26, 2020 edited

Hello Team,

I have an issue of the type Initiate which is linked to an issue type Automation. I want a script listener which would update a custom field for the type Automation if it updated in the issue type Initiate.  Actual End Date and Actual Start Date are the two fields that are to be updated.

I have tried writing a script below. But it updating the same issue, which is of the issue type Initiate. Please help me with this. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issue = event.getIssue()def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.warn("Issue updated event triggered listener")
IssueManager issueManager = ComponentAccessor.getIssueManager()

def changeHolder = new DefaultIssueChangeHolder()
def actualStartDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10400")
def actualEndDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10400")
def issueLinkManager = ComponentAccessor.getComponent(IssueLinkManager)
if(issue.issueType.name.equals("Automation"))
{
log.warn("Entered the Loop")
actualStartDate.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(actualStartDate), actualStartDate), changeHolder)
actualEndDate.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(actualEndDate), actualEndDate), changeHolder)
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events