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

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

helen levich Apr 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

0 votes
Answer accepted
Peter-Dave Sheehan Apr 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.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Opsgenie

Handling Opsgenie Alerts

Hi everyone, welcome to the kb articles for Opsgenie FAQs. I'm one of the Technical Support Engineers for Opsgenie who will be providing weekly posts on FAQs from customers.   All alerts are ...

58 views 0 2
Read article

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