This piece is with regards to a Severity Matrix for our customer raised issues.
The following works fine via a script runner post function
import com.atlassian.jira.component.ComponentAccessor
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Severity")
def cfConfig = cfSelect.getRelevantConfig(issue)
def ImpactField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10222")
def ImpactValue = (String)issue.getCustomFieldValue(ImpactField);
log.info("Priority:" + issue.priority.name )
log.info("Impact:" + ImpactValue )
def SeverityID = '0'
def IssueSeverity = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == SeverityID
}
if (ImpactValue == "Company (All)") {
if (issue.priority.name == "Critical") { SeverityID = '1'}
if (issue.priority.name == "Major") { SeverityID = '2'}
if (issue.priority.name == "Minor") { SeverityID = '3'}
}
if (ImpactValue == "Department (more than 1)") {
if (issue.priority.name == "Critical") { SeverityID = '2'}
if (issue.priority.name == "Major") { SeverityID = '2'}
if (issue.priority.name == "Minor") { SeverityID = '3'}
}
if (ImpactValue == "Individual") {
if (issue.priority.name == "Critical") { SeverityID = '3'}
if (issue.priority.name == "Major") { SeverityID = '3'}
if (issue.priority.name == "Minor") { SeverityID = '3'}
}
IssueSeverity = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == SeverityID
}
log.info("Severity Set To:" + SeverityID )
issue.setCustomFieldValue(cfSelect, IssueSeverity)
This works a treat on issue creation. This is saved as a file in the script editor within Scriptrunner.
Now we need this to run whenever the Priority or Impact fileds are changed, my first attempt with a ScriptRunner Listner does not seem to work, though it appears to running the file.
Hi @David Harkins Issue Events work with IssueEvent object. It is described in script runner docs: https://scriptrunner.adaptavist.com/5.6.8/jira/listeners.html#_custom_listeners
So at least you will need to get instance of an issue with:
def issue = event.issue
@Martin Bayer _MoroSystems_ s_r_o__
Is that then a modification the existing working code or do i need to duplicate it with some differences?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can't simply reuse whole postfunction because listener works with different "core" object.
But you do not need to duplicate all the code. You can create groovy class and use it. This class can contain almost all the code. DO you have some experiences with groovy/java or you need more help?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Only experience I have is the pieces I have picked up
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, try to duplicate the code first. It should be something like:
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Severity")
def cfConfig = cfSelect.getRelevantConfig(issue)
def ImpactField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10222")
def ImpactValue = (String)issue.getCustomFieldValue(ImpactField);
log.info("Priority:" + issue.priority.name )
log.info("Impact:" + ImpactValue )
def SeverityID = '0'
def IssueSeverity = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == SeverityID
}
if (ImpactValue == "Company (All)") {
if (issue.priority.name == "Critical") { SeverityID = '1'}
if (issue.priority.name == "Major") { SeverityID = '2'}
if (issue.priority.name == "Minor") { SeverityID = '3'}
}
if (ImpactValue == "Department (more than 1)") {
if (issue.priority.name == "Critical") { SeverityID = '2'}
if (issue.priority.name == "Major") { SeverityID = '2'}
if (issue.priority.name == "Minor") { SeverityID = '3'}
}
if (ImpactValue == "Individual") {
if (issue.priority.name == "Critical") { SeverityID = '3'}
if (issue.priority.name == "Major") { SeverityID = '3'}
if (issue.priority.name == "Minor") { SeverityID = '3'}
}
IssueSeverity = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
it.toString() == SeverityID
}
log.info("Severity Set To:" + SeverityID )
issue.setCustomFieldValue(cfSelect, IssueSeverity)
give it a try and we can try to work on it... but unfortunetally I'm not able to teach you basics of object-oriented programming :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.