Is there any way to read the work log of linked Issues and fill the sum of such work in a field?

Desarrollo_3digits May 25, 2018

We're working with an organization where their structure works with the fact that a single Issue may have one or many linked Issues, each linked issue has a set of one or more subtasks. All these subtasks are logged in the total log work of each linked Issue.

 

We have been tasked on calculating the sum of the work logged all these linked issues into a single custom field called "Progress" so we can display it on a Dashboard for their direction.

I'll put an example to sum it up:

Imagine we have the Issue Main. Main has 3 linked issues: A, B and C.

Each linked Issue has 5 subtasks, and each of them are logged in it's logged work

we have a custom field named Progress which is resting in Main currently empty. We want to make the sum of the logged work of A, B And C to appear inside this custom field.

 

May be worth nothing that we have recently adquired a trial version of Adaptavist ScriptRunner attempting to find a way to do this but we're not having any luck at all, none of us ever coded with Groovy and it's coming up as somewhat difficult to progress through with, we've seen a few code works on the net but none seemed to work for what we want.

 

Any help or pointing towards the right direction would be heavily appreciated.

 

Thank you in advance.

1 answer

0 votes
Danyal Iqbal
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.
May 25, 2018

 

Is it going to be a post function or is it going to run in script console.

I doubt anyone here would write out the complete code for you, but I can give some useful hints. You need to get back to the documentation. Start with this example and than increment it slowly: https://scriptrunner.adaptavist.com/latest/jira/recipes/scriptfields/workRemainingInLinkedIssues.html

1. Get the linked issues of main:


def issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueObject("main-1")  
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

            for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
                IssueLink issueLink = (IssueLink) outIterator.next();
                String key = issueLink.getDestinationObject().getKey();
               log.warn("linked issued:: "+key)
}

               

2. Get subtasks of all linked issues:

Collection subTasks = issue.getSubTaskObjects()

3. Get/Sum Customfields/ logged work:

def cfm = componentManager.getCustomFieldManager()
subTasks.each {
def cf= it?.getCustomFieldValue(cfm?.getCustomFieldObjectByName("customfield_xx"))
def linkedIssueTimeSpent = it?.timeSpent
totalTimeSpent += linkedIssueTimeSpent
}

4. set Field on main issue:

def String inprogress= totalTimeSpent 
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def textCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "fieldname_here"}
if (textCf) {
    def changeHolder = new DefaultIssueChangeHolder()
    textCf2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(textCf), inprogress),changeHolder)
}
Desarrollo_3digits May 28, 2018

Greetings, @Danyal Iqbal, thank you for your answer, it is going to run in the script console as it has to fill the field automatically whenever the users log work and that's independant of the workflow.

 

Kind Regards

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 28, 2018

>it is going to run in the script console as it has to fill the field automatically whenever the users log work

That's wrong.  Are you really going to log in as an admin and run the script every time a user clicks "log work"?

You should have a think about the field this data is to go into.  If it's something the users should be able to edit (which I doubt), then you need to write this as a listener or possibly a behaviour, if it's just a pre-fill.  If it is not for editing, write it as a scripted field.

Danyal Iqbal
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.
May 28, 2018

script console is not the appropriate palce for such a script. I would use a scripted field for this.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events