Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Add comments to all issues under epic and updated the epic status to all linked issue to that epic

srinivas kattla February 18, 2020

Hello All,

I'm trying to add the comment to all issues linked to the current issue through the is Epic of (from Epic to Stories) link type with the following text: This Story/Task has been set to reopened as the linked Epic has been re-opened. If this is not correct .

And I want to update the epic status to all the linked issues.

The is a post function 

 

The script is not working and I'm not sure which issue linked type is selected as I don't see issue link type epic of stories. The script is not working 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.link.IssueLinkManager

 

def userManager = ComponentAccessor.getUserManager()

def user = userManager.getUserByKey("testing maintenance")

def comment = "The Defect that was blocking the progress of this item has been closed, please can you provide an update to see if this can now be progressed."

def commentManager = ComponentAccessor.commentManager

 

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()

 

issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->

    def linkedIssue = issueLink.getSourceObject()

    if (issueLink.getIssueLinkType().getName().equals("Defect")){

        commentManager.create(linkedIssue, user, comment, true)

    }}

 

issueLinkManager.getOutwardLinks(issue.getId()).each {issueLink ->

    def linkedIssue = issueLink.getDestinationObject()

    if (issueLink.getIssueLinkType().getName().equals("Defect")){

        commentManager.create(linkedIssue, user, comment, true)

    }}

 

Can you please suggest .

Thanks

Sri

 

1 answer

1 vote
PD Sheehan
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.
February 18, 2020

Hi @srinivas kattla 

Epics and issuesInEpic are not linked via the regular issueLinkManager.

If you want to get all the issues in an epic, you need the epicLinkManager but since this is provided by (as quoted from the scriptrunner documentation) "JIRA Agile, or TAFKAG (the add-on formerly known as Greenhopper)" you need to get this manager a little differently than regular components.

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager

@WithPlugin("com.pyxis.greenhopper.jira")

@JiraAgileBean
EpicLinkManager epicLinkManager

def epic = ComponentAccessor.issueManager.getIssueObject('JSP-4481')
def issuesInEpic = epicLinkManager.getIssuesInEpic(epic)
srinivas kattla February 20, 2020

Hi Peter I tried the posted script but showing some errors I will check it to fix it .

srinivas kattla February 24, 2020

@PD Sheehan  : It ididn't work.Trying to find it .Please let me know if you are able o make it.

PD Sheehan
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.
February 24, 2020

Can you explain a bit more about what type of errors you are getting? Perhaps include screenshots or log outputs.

My script above was only an example that works in the console. Try it in your scriptrunner console (but put in the key for one of your known epic with issues).

If your script is in a post-function and the current issue is a story/task and you want to get the epic, then you need to use the epicLink field to get that epic.

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager
import com.atlassian.jira.issue.Issue


@WithPlugin("com.pyxis.greenhopper.jira")

@JiraAgileBean
EpicLinkManager epicLinkManager

def issue = ComponentAccessor.issueManager.getIssueObject('JSP-1922')
//get the epic link field
def customFieldManager = ComponentAccessor.customFieldManager
def epicLinkCf = customFieldManager.getCustomFieldObjects(issue).find{it.name == 'Epic Link'}

//get the epic from the current issue
def epic = issue.getCustomFieldValue(epicLinkCf) as Issue

def issuesInEpic = epicLinkManager.getIssuesInEpic(epic)

issuesInEpic.each { issueInEpic ->
    //do something on each issues in the epic
}
Like Peter Cook likes this
srinivas kattla February 25, 2020

@PD Sheehan  : Now I don't see any comments adding to issues in epic. Here is the script that I update. and error below.

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager
import com.atlassian.jira.issue.Issue


@WithPlugin("com.pyxis.greenhopper.jira")

@JiraAgileBean
EpicLinkManager epicLinkManager

def issue = ComponentAccessor.issueManager.getIssueObject('PD-5700')
//get the epic link field
def customFieldManager = ComponentAccessor.customFieldManager
def epicLinkCf = customFieldManager.getCustomFieldObjects(issue).find{it.name == 'Epic Link'}

//get the epic from the current issue
def epic = issue.getCustomFieldValue(epicLinkCf) as Issue

def issuesInEpic = epicLinkManager.getIssuesInEpic(epic)

issuesInEpic.each { issueInEpic ->
//do something on each issues in the epic
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByKey("ds.pmo")
def comment = "This Story/Task has been set to reopened as the linked Epic has been re-opened. If this is not correct please set to Descoped."
def commentManager = ComponentAccessor.commentManager
}

 

Error 

Time (on server): Tue Feb 25 2020 12:33:46 GMT-0600 (Central Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2020-02-25 18:33:46,766 ERROR [workflow.AbstractScriptWorkflowFunction]: *************************************************************************************
2020-02-25 18:33:46,767 ERROR [workflow.AbstractScriptWorkflowFunction]: Script function failed on issue: PB-5700, actionId: 211, file: null
groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.atlassian.jira.issue.managers.CachingCustomFieldManager#getCustomFieldObjects.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
 [interface com.atlassian.jira.issue.Issue]
 [interface com.atlassian.jira.issue.search.SearchContext]
 at Script298.run(Script298.groovy:16)
PD Sheehan
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.
February 25, 2020

Which issue type is this workflow post-action acting on? Is this on the epic, or one of the sub-tasks?

I think the error you are getting is from trying to overwrite the value of issue which is already defined in the script scope for you and represents the issue that the workflow is currently working on. And, in the script, you've attempted to hard code the issue to PD--5700 but the log shows that the current issue being acted on is PB-5700

So depending on whether the workflow is on the epic, or one of it's linked issues, you may need to make some adjustments.:

If the current issue is not an epic, then try to just remove this line:

def issue = ComponentAccessor.issueManager.getIssueObject('PD-5700')

If the current issue is the epic, and you want to add comments to all the issues in the epic, remove the line above and the next two lines and replace the "def epic =..." line with

def epic = issue 

Also, you will need to actually create the comment:

issuesInEpic.each { issueInEpic ->
//do something on each issues in the epic
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByKey("p6s")
def comment = "This Story/Task has been set to reopened as the linked Epic has been re-opened. If this is not correct please set to Descoped."
def commentManager = ComponentAccessor.commentManager
   commentManager.create(issueInEpic, user, comment,false)
}
srinivas kattla February 25, 2020

Thanks @PD Sheehan . I was able to make with the script working as suggested but want update the status of epic and issue in the epic status to Descoped.Can you please suggest.

srinivas kattla February 27, 2020

@PD Sheehan  :  question ,I want to update the status to Reopen for all issues in the epic.Can you let me know.

PD Sheehan
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.
February 27, 2020

Hi, sorry, I'm been very busy with a project at work.

You can't just change the status with scriptrunner, you have to trigger a workflow transition. That get rather more complicated than I have time to get into right now.

There may be required fields and a transition screen to contend with etc.

I'd suggest you search for solution around this topic or ask a new question.

Here is an example that might help you get started: https://community.atlassian.com/t5/Marketplace-Apps-Integrations/transition-issue-after-transition-post-function/qaq-p/1280845

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events