We created a issue type "work package" and we want to copy the original estimate (sum of stories in structure under this issue type) on the transition to a status "baselined" in a custom field.
Can someone please help me with the inline script for the scripted field we need to create for the custom field (created via scriptrunner).
(And is there somehow a possibility to lock this field after the transition?)
The complete code for your needs:
enableCache = {-> false}
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def issueLinks = issueLinkManager.getOutwardLinks(issue.getId())
def subElements = issueLinks.findAll { it.issueLinkType.name == 'Work package' }
def totalStoriesEstimation = 0
for (def i = 0; i < subElements.size(); i++ ) {
totalStoriesEstimation = totalStoriesEstimation + issueManager.getIssueObject(subElements[i].destinationId).getOriginalEstimate()/3600/8
}
return totalStoriesEstimation
:)
Hi,
To understand your needs.
you have epic with multiple stories, and you want to see inside the epic the sum of original estimate of all the stories in it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi :)
yes - but this we already have.
We want to "save" the value of the original estimate in a separate field after a specific status is reached. We are using an issue type called work package, which summarises via structure the estimates like the epics.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK,
I don't understand why you need it, but fine :)
Do you want it to happen after an Epic reached to a specific status or when Story reach to a specific status?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
we don't use epics in our customer projects, we use the issue type work package there - and when the work package reaches a status, we need to have the sum of the original estimate in a separate field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So basically my problem is, that I'm not able to configure a custom field with the setting, that I'm able to copy the original estimate into this field via a workflow post function. I used a scripted field from scriptrunner.. but when I select "duration (time tracking)" as field type, I need to fill in inline script or a path to a script - and I don't know what I need to do there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
in the inline script write this:
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor
def changeHolder = new DefaultIssueChangeHolder();
def tgtField = customFieldManager.getCustomFieldObject("customfield_11111") /*replace customfield_11111 with your field id*/
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), issue.getOriginalEstimate()),changeHolder);
This will update your customfield with the value of your originalEstimate of the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is is possible to add to this script, that it only copies the value on the transition to the status baselined? because otherwise it will update every time the value changes..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure...
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor
if (issue.getStatus().getName() == "baselined") {
def changeHolder = new DefaultIssueChangeHolder();
def tgtField = customFieldManager.getCustomFieldObject("customfield_11111") /*replace customfield_11111 with your field id*/
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), issue.getOriginalEstimate()),changeHolder);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I get some errors then: (with the right number for the custom field)
def tgtField = customFieldManager.getCustomFieldObject("customfield_11111")
Static type checking - the variable customfieldmanager is undeclared.
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), issue.getOriginalEstimate()),changeHolder);
Cannot find matching method com.atlassain.jira.issue.issue#getcustomfieldvalue (java.lang.obect). Please check if the declared type is right and if the method exists.
Cannot find matching method java.lang.object#updatevalue(<unknown parameter type>, com.atlassian.jira.issue.issue, com.atlassian,jira.issue.modifiedvalue, com.atlassian.jira.issue.util.deufaltissuechangeholder. please check if the declared type is right and if the method exists.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You right,
i missed something, here is the complete code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
if (issue.getStatus().getName() == "baselined") {
def changeHolder = new DefaultIssueChangeHolder();
def tgtField = customFieldManager.getCustomFieldObject("customfield_11111") /*replace customfield_11111 with your field id*/
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), issue.getOriginalEstimate()),changeHolder);
}
checked it on my instance and it works
Just don't forget to replace the "customfield_11111" with the id of your field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, sorry for the late reply.
This is what I have now:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
if (issue.getStatus().getName() == "baselined") {
def changeHolder = new DefaultIssueChangeHolder();
def tgtField = customFieldManager.getCustomFieldObject("customfield_12412")
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), issue.getOriginalEstimate()),changeHolder);
}
But there is nothing happening during the transition to baselined.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In which step of your post-function did you put your script?
Try to put it one above the "Re-index an issue to keep indexes in sync with the database."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh - in a postfunction?
I have put it in the "script" section in scriptrunner for the scripted fields.
Because I need the custom field with the possibility have values as duration in the fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have skype? talking in chat mode it will be more easy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes - I send you an linkedin request to add me (Eva) - so we can exchange the Skype addresses there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I rejected your request by mistake, can you send again? :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sent you connection request, please approve, otherwise we can't message to each other.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nir Haimov I am facing the same issue and I kept the code in script post function but the code is not working for me.
Can you help me here please?
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.