Duplicated comment added during transition

Arianna Fabbri November 9, 2014

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
Answer accepted
JamieA
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.
November 10, 2014

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
JamieA
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.
November 10, 2014

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
TAGS
AUG Leaders

Atlassian Community Events