Hi,
I found in other questions here, an answer which partially cover my question (https://answers.atlassian.com/questions/165598), but I want to have this to work only for linked issues with "Epic link", so I made some modification in code:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.component.ComponentAccessor; def componentManager = ComponentManager.getInstance() def issueLinkManager = componentManager.getIssueLinkManager() def cfManager = ComponentManager.getInstance().getCustomFieldManager() double totalSP = 0 customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points"); log.debug("${customField.id}") issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink -> if (issueLink.issueLinkType.name == "Epic-Story Link") { def SP = issueLink.destinationObject.getCustomFieldValue(customField) ?: 0 totalSP += SP }} return totalSP
But it does not seem to work - when changing Story Points of some issues liked with epic link this scripted custom field displays random values (when refreshing page this value changes).
Do you have any clue where I made a mistake? (nothing found in logs)
(JIRA version 6.4.12, Service Runner - 3.1.4, scripted field use: Number Searcher and Number Field Template)
Thanks,
Paulina
Paulina
Can you try the code below and tell me if this works for you?
import com.atlassian.jira.component.ComponentAccessor; enableCache = {-> false} def issueLinkManager = ComponentAccessor.getIssueLinkManager() def totalSP = 0.0 log.debug("${customField.id}") log.debug("Issue ${issue}") issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink -> if (issueLink.issueLinkType.name == "Epic-Story Link") { customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points") def SP = issueLink.destinationObject.getCustomFieldValue(customField) as Double ?: 0.0 log.debug("SP value ${SP}") totalSP += SP }} return totalSP as Double
I checked this one and unfortunately have same situation. But what I observed - this scripted field is placed in view screen of Epic - as I wrote before when I am changing story points in stories (they are linked to this Epic with epic link), this situation with random values occurs, but then if I edit this Epic - correct value is displayed and when refreshing no random values appear - it stays in proper value. Is it possible that some kind of _indexing_ is missing from Epic level (as Epic is not edited but stories linked to it)? if yes how should I include it in this scripted field? Sorry if my explanation is not clear:) Paulina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Paulina, Sorry for the delay, could you please try to disable caching ? https://scriptrunner.adaptavist.com/4.2.0.2-SNAPSHOT/jira/scripted-fields.html#_more_advanced_notes_on_caching
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist], Thanks very much for your support! It started to work after applying "enableCache = {-> false}" in my code . Do you know if this cache disabling have any influence on jira performance (we have very big production instance)? Also there is written in page which you sent to me that it should be fixed in 2.1.4 version (we are using ScriptRunner v 3.1.4). Br, Paulina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist],
First, I want to thank you once again for your support and if you convert your comment to answer I will accept it.
However I have one question - after implementation of this field I need to limit it for Story issue type for one project (users of this project are using SP in different way as rest of users and they do not want to be counted in my field).
What I did? - I added condition to if loop as here:
import com.atlassian.jira.component.ComponentAccessor; def issueLinkManager = ComponentAccessor.getIssueLinkManager() def totalSP = 0.0 enableCache = {-> false} log.debug("${customField.id}") log.debug("Issue ${issue}") issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink -> //below I tried to exclude Story from TEST project if ((issueLink.issueLinkType.name == "Epic-Story Link" && (!(issue.projectObject.key in ["TEST"] && issue.issueTypeObject.name == "Story")))) { customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Story Points") def SP = issueLink.destinationObject.getCustomFieldValue(customField) as Double ?: 0.0 log.debug("SP value ${SP}") totalSP += SP }} return totalSP as Double
But it seems not to work properly - Story Points of Stories from TEST project are still counted in my field.
My scripted field "Sum of SP" is visible in Epic issue type and should display all Story Points of linked with "Epic link" issues except of Stories from TEST project.
What do you think, is it possible? if yes, where I made a mistake in my code?
Thanks in advance for your support!
We recently updated our Script Runner to 4.1.3.7 and must say that those additional functions are great!
Best regards,
Paulina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi to all,
I have some trouble implementing this scripted field in JIRA 7.0 ... has anyone ever done it?
Regards,
Mathieu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's okay, I managed it after some research.
Just in case anyone needs it (adapted in case some user stories have no value at all) :
import com.atlassian.jira.ComponentManager import com.atlassian.jira.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.component.ComponentAccessor; def componentManager = ComponentManager.getInstance() def issueLinkManager = ComponentAccessor.getIssueLinkManager() def cfManager = ComponentAccessor.getCustomFieldManager() double totalSP = 0 customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10259"); if (issue.getIssueTypeId() != "10 100") { return null } issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink -> if (issueLink.issueLinkType.name == "Epic-Story Link" ) { double SP = (double)(issueLink.destinationObject.getCustomFieldValue(customField) ?: 0) totalSP = SP + totalSP; }} return totalSP
Also the log. doesn't seem to work at all.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried the above, and it compiles and executes with no error, but always returns null. I'm not really sure what the "10 100" is for, but I substituted 6 (no quotes), which is the ID for Epic in our system. I'd really like to get this working. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I know this reply is about 3 yrs too late, but I needed to create a field like this and stumbled across this posting. I needed to make some slight edits in the code above to get it working. Here's what is working flawlessly for me now. Be sure to put in the correct custom field id for your Story Point field. Also, the Epic issue type normally has an id of 10000, but if yours is different, change that too.
Hopefully this will help someone.
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor;
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
double totalSP = 0
customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10106");
if (issue.getIssueTypeId() != "10000") {
return null
}
issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->;
if (issueLink.issueLinkType.name == "Epic-Story Link" ) {
double SP = (double)(issueLink.destinationObject.getCustomFieldValue(customField) ?: 0)
totalSP = SP + totalSP;
}}
return totalSP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist], Thanks for quick reply - I changed it to 0.0 and it still it does not work... Yes, random values are displayed when viewing baseUrl/jira/browse/<issue> (only to this view screen my scripted field is added). By "random values" I mean - after change of story points of linked with epic link issue -> when refreshing issue page, once previous value is displayed, once correct one, after next change there are three values: 1st one, 2nd and correct one -and so on). Paulina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Paulina, Can you try to replace 0 with double values 0.0 (even though I am not sure that this is the reason)? Also in which screen/s you see random values, for example when you are viewing the baseUrl/jira/browse/<issue> ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline 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.