You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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())
}
Error on line 30
Issue epic = event.issue.getCustomFieldValue(epicLink);
Error on line 40
if(link.getDestinationObject().getFixVersions().toArray()[0].getId() != epic.getFixVersions().toArray()[0].getId())
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.