Scripted costumefield which "ask" about fields of epic

I need to create new scripted costumefield called "category".

 

it should work like this:

 

 

If issue type = bug -> category = "bug"

· elseIf issue."Request type"="External" -> category="external"

· elseIf issue."Request type"="Operations" -> category="Ops"

· elseIf issue.epic(parent).Theme="No Theme" -> category="no Theme"

· elseIf issue.epic(parent).Theme is one of these("Security", "Platform OS", "Stability and endurance", "End to end performance", "R&D: Infra", "R&D: Dev Cycle", "OhioBox") or issue type="technical debt" -> category="Production"

· else category="Themes"

*Request type is a "single choice costume field"

*Theme is a "single choese costumfield" which Only the Epic level have

 

Does anyone knows how i make condition on value from Epic level (father of Story/taks)?

 

thanks,

 

Liran

1 answer

This widget could not be displayed.

Hi Liran,

This code will retireve the epic object linked to the issue that the 'Category' scripted field is in. It then gets the value of the 'Theme' custom field for the linked epic. From there you can you do your if checks on the theme value and the if checks on your 'Request Type', as you have both the main issue and the linked epic issue available to query.

 

def mainIssue = issue
def IM = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epic = customFieldManager.getCustomFieldObjectByName("Epic Link")
def theme = customFieldManager.getCustomFieldObjectByName("Theme")
def epicLink = mainIssue.getCustomFieldValue(epic)
def epicObject = IM.getIssueObject(epicLink?.toString())
def themeValue = epicObject.getCustomFieldValue(theme)

Let me know if this helps.

Thanks.

thanks for the quick answer!!!

tried it and it doesn't work.

this is my code:

import groovy.xml.MarkupBuilder
import java.util.*
import javax.swing.text.*;
import javax.swing.text.html.*;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager


def mainIssue = issue
def IM = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epic = customFieldManager.getCustomFieldObjectByName("Epic Link")
def theme = customFieldManager.getCustomFieldObjectByName("Theme/Project/Think IT")
def epicLink = mainIssue.getCustomFieldValue(epic)
def epicObject = IM.getIssueObject(epicLink?.toString())
def themeValue = epicObject.getCustomFieldValue(theme)

 

if (issue.getIssueType().name== "Bug")
{
return "Bug";
}
else
customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_13328")
if ((String)issue.getCustomFieldValue(customField) == "External request")
{
return "External";
}
else
customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_13328")
if ((String)issue.getCustomFieldValue(customField) == "Operations request")
{
return "Operations";
}
else
if (themeValue == "**No Theme**")
{
return "**No Theme**";
}
else
if (themeValue == "*Security*"||themeValue == "*Platform OS*"||themeValue == "*End to End Performance*"||themeValue == "*Stability and load endurance*"||themeValue == "R&D: Dev Cycle"||themeValue == "R&D: Infra"||themeValue == "OhioBox"||themeValue== "Technical Debt")
{
return "Production";
}
else
return "Themes"

 

it works good except the theme part - any ideas why?

 

the problem was i needed to do String casting - now works - thank you very much!

No problem. Glad I could help.

Could you please mark this quuestion as answered now. Thanks!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 14 hours ago in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

41 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you