SriptRunner custom listener that sets status on epic to "Documenting" after all children are closed

helen levich
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 23, 2019

After upgrade of Jira to 7/ScriptRunner to 5, existing ScriptRunner custom listener stopped working. Listener was setting status on parent epic to "Documenting" when status on all child objects were set to "Closed".

Script give two static errors and does not work in new version. 

Any suggestions will be greatly appreciate. 

Thank you 

 

import org.apache.log4j.Logger;
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category

import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink;

//Issue Service
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.component.ComponentAccessor


// Logger
Logger log = Logger.getLogger("EPICLINK::");
// Set the logging level to INFO/DEBUG as needed
log.setLevel(org.apache.log4j.Level.DEBUG);
def logPrefix = "EPICLINK:: ";
logPrefix = logPrefix + event.issue.getKey() + ":: ";

log.debug(logPrefix)

try
{
log.debug(logPrefix + "TRY Block... START")
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
Issue epic = event.issue.getCustomFieldValue(epicLink);

if(epic)
{
log.debug(logPrefix + "Epic Link Key:: " + epic.getKey())
def linkMgr = ComponentAccessor.getIssueLinkManager();
def blnNotClosed = false

for (IssueLink link in linkMgr.getOutwardLinks(epic.getId()))
{
if(link.getDestinationObject().getFixVersions().toArray()[0].getId() != epic.getFixVersions().toArray()[0].getId())
{
blnNotClosed = true;
break;

}
if(link.getDestinationObject().getStatus().getName() != "Closed")
{
blnNotClosed = true;
break;
}
}

if(!blnNotClosed)
{
log.warn("TRANSITION EPIC!!!!!!!")
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(loggedInUser, epic.getId(), 821,issueInputParameters);
if (transitionValidationResult.isValid())
{

IssueService.IssueResult updateResult = issueService.transition(loggedInUser, transitionValidationResult);
if (!updateResult.isValid())
{
if (updateResult.getErrorCollection().hasAnyErrors())
{
int i = 1;
Iterator itr = updateResult.getErrorCollection().getErrors().entrySet().iterator();
while (itr.hasNext()) {
Map.Entry mapEntry = (Map.Entry) itr.next();
log.error(logPrefix + "transition FAIL issue: [err_msg_"+i+"]["+mapEntry.getKey() +"]["+ mapEntry.getValue()+"]")
i++;
}
}
}
else
{
log.debug(logPrefix + "transition Success...")
}
}
else
{
if (transitionValidationResult.getErrorCollection().hasAnyErrors())
{
int i = 1;
Iterator itr = transitionValidationResult.getErrorCollection().getErrors().entrySet().iterator();
while (itr.hasNext()) {
Map.Entry mapEntry = (Map.Entry) itr.next();
log.error(logPrefix + "transition FAIL issue: [err_msg_"+i+"]["+mapEntry.getKey() +"]["+ mapEntry.getValue()+"]")
i++;
}
}
}
}

}
log.debug(logPrefix + "TRY Block... END")
}

catch(Exception e)
{
log.error(e.getMessage())
}

image.png

Error on line 30

Issue epic = event.issue.getCustomFieldValue(epicLink);

image.pngError on line 40 

if(link.getDestinationObject().getFixVersions().toArray()[0].getId() != epic.getFixVersions().toArray()[0].getId())

image.png

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 26, 2019

I generally ignore static type checking errors. These can help with debugging your code, but they don't automatically mean that your code is bad.

I would run it and look at the specific line that's failing by reviewing the logs.

TAGS
AUG Leaders

Atlassian Community Events