Hey everyone,
Forgive the long question. I'm working on Groovy script to set the value of a custom field (Incident or Request) based on the choice in a different custom field(s).
This is a first attempt and is fairly messy, but as it stands, we have four different Issue Types, Hardware, Software, Permissions, and Misc. Each of these types has a custom field asking the user a question that boils down to "Is this something new or is something broken?"
Due to the nature of the different forms, the custom fields aren't the exact same, so I had to call the content of the form's custom field in order to give Incident or Request something to work off of.
The script "works", right now it sets everything to Incident. Which is half the battle, but not everything is an incident! Please find the attempted script below:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueMgr = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cf = customFieldManager.getCustomFieldObjectByName("Incident or Request")
def cFieldValueHardware = customFieldManager.getCustomFieldObjectByName("Hardware Issue Type").getValue(issue)
def cfMiscType = customFieldManager.getCustomFieldObjectByName("Misc Ticket Type")
def cfPermType = customFieldManager.getCustomFieldObjectByName("Permissions Ticket Type")
def cfSoftwareType = customFieldManager.getCustomFieldObjectByName("Software Issue Type")
def cFieldValueMisc = issue.getCustomFieldValue(cfMiscType)
def cFieldValuePerm = issue.getCustomFieldValue(cfPermType)
def cFieldValueSoftware = issue.getCustomFieldValue(cfSoftwareType)
def fieldConfig = cf.getRelevantConfig(issue)
def value = 'Request'
if(cFieldValueHardware == "I need something!" || cFieldValueMisc == "I need something" || cFieldValuePerm == "I need access to something" || cFieldValueSoftware == "I need some software")
value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Request' }
else
value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'Incident' }
I've dug through the forums and found plenty of questions about changing custom fields with Groovy but I can't find anything that's exactly this situation. Does anyone have any ideas on how I could tweak this to work better? Or glaring gaps in what's been put together?
Please let me know if you need any additional information to rescue me!
Thanks.