It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Update newly linked issue tempo custom field

I'm attempting to update the Tempo Account custom field of a linked issue during the IssueLinkCreatedEvent. The below code executes successfully, but does not update the account field. I am using Custom Listener inside of scriptrunner

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.INFO)

def CustomFieldManager = ComponentAccessor.getCustomFieldManager()

def IssueManager = ComponentAccessor.getIssueManager()

def event = event as IssueLinkCreatedEvent

def sourceIssue = event.getIssueLink().getSourceObject()
log.info("sourceIssue: " + sourceIssue.key)

IssueService issueService = ComponentAccessor.getIssueService()

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();


if (sourceIssue.issueType.name != "Epic"){
log.info("Exiting ... sourceIssue type of" +sourceIssue)
}

MutableIssue issue = event.getIssueLink().getDestinationObject() as MutableIssue

log.info("issue: " + issue.key)

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def CfAccount = customFieldManager.getCustomFieldObjectByName("Account")
log.info("CfAccount: " + CfAccount)
def cfValue = event.issueLink.sourceObject.getCustomFieldValue(CfAccount)
log.info("Epic Account Value: "+cfValue)
def issueAccount = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Account"}

if(issue){

issueInputParameters.addCustomFieldValue(issueAccount.getIdAsLong(),cfValue.toString());

ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
UpdateValidationResult validationResult = issueService.validateUpdate(loggedInUser, issue.getId(), issueInputParameters);
if (validationResult.isValid()){
IssueResult result = issueService.update(loggedInUser, validationResult);
}

}

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

273 views 1 2
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you