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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
script console is not the appropriate palce for such a script. I would use a scripted field for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.