Duplicated comment added during transition

Good morning,

I'm running the below script but I'm not understanding why the target issue is updated with duplicated comment

import [...]

log = Category.getInstance("com.onresolve.jira.groovy.CreateDependentIssue")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "Debug statements " + issue.id

def BEprojectName = issue.getProjectObject().name
def SDProjectName = BEprojectName.substring(8,BEprojectName.length())
log.debug "BEProject: " + BEprojectName
log.debug "SDProject: " + SDProjectName

// Variables definition
ComponentManager             componentManager =         ComponentManager.getInstance()
IssueManager                 issueManager =             componentManager.getIssueManager()
ProjectManager                 projectManager =         componentManager.getProjectManager()
IssueFactory                 issueFactory =             componentManager.getIssueFactory()
JiraAuthenticationContext     authContext =             componentManager.getJiraAuthenticationContext()
CustomFieldManager             customFieldManager =     componentManager.getCustomFieldManager()
IssueIndexManager            indexManager =             componentManager.getIndexManager()
JiraWorkflow                 workflow =                 componentManager.getWorkflowManager().getWorkflow(issue)
IssueLinkManager             issueLinkManager =         componentManager.getIssueLinkManager()
IssueService                 issueService =             componentManager.getIssueService()
    
UserManager                 userManager =             (UserManager) ComponentAccessor.getUserManager()
    
IssueChangeHolder             changeHolder =             new DefaultIssueChangeHolder()

def wasIndexing = ImportUtils.indexIssues
ImportUtils.indexIssues = true

boolean existingLinkedCode = false

for (IssueLink issueLink in issueLinkManager.getInwardLinks(issue.id)){
    if(issueLink.issueLinkType.name == "Trigger"){
        existingLinkedCode = true
        
        SDIssue = issueLink.sourceObject  
        String SDIssueKey = SDIssue.key
        log.debug "Inward linked issue: " + SDIssue.key
        
    }
}
log.debug ("Search result: " + existingLinkedCode)

// Transition on original issue
if(existingLinkedCode == true){

    // Workflow Transition: extract details from transition properties (ex. user comment, transitionID, assignee...)
    def wfd = workflow.getDescriptor()
    def transitionComment = transientVars["comment"]
    def actionId = transientVars["actionId"]
    log.debug "comment: " + transitionComment 
    log.debug transientVars

    log.debug("Update original issue's status")
    def com.atlassian.crowd.embedded.api.User currentUser = ComponentManager.instance.jiraAuthenticationContext.getLoggedInUser()
    
    // Define parameters needed during issue workflow transition
    IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
    issueInputParameters.setSkipScreenCheck(true)
    issueInputParameters.setComment(transitionComment)
    
    IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(currentUser, SDIssue.getId(), actionId, issueInputParameters)
    
    if (transitionValidationResult.isValid())
    {
        log.debug "Transition Validation VALID"
        def transitionResult = issueService.transition(currentUser, transitionValidationResult)
        if (!transitionResult.isValid())
        {
            log.debug "Transition result INVALID"
        }else{
            ComponentAccessor.getIssueIndexManager().reIndex(transitionValidationResult.getIssue())
            log.debug "Transition result VALID"            
        }
    }else{
        log.debug "Transition Validation INVALID"
    }
}else{
    log.debug("No existing links")
}

In my log file:

Debug statements 17478
BEProject: Backend ZS Support
SDProject: ZS Support
Inward linked issue: ZS-17
Search Result: true
comment: Commento
update original issue's status
Transition Validation VALID
Transition result VALID

When I open the new linked issue I see comment "Commento" twice.

 

Why this?

 

Thank in advance for your help

 

2 answers

1 accepted

1 vote

And regarding why you see the log statements twice, are you running this as a listener? It will run for the source issue and the issue you update, sunject to which events you are listening for, same applies to workflow functions if the target issue has the same workflow. 

1 vote

There is a bug in jira, it's related to skipScreenCheck. If you remove that, and you have a screen for that transition, you will only get the comment once.

Basically skipScreenCheck doesn't seem to work properly: https://jira.atlassian.com/browse/JRA-31690.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

143 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you