Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

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

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 Community Leader 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)
}

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

>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 Community Leader 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
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,873 views 11 5
Join discussion

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