Hello All,
I'm trying to write a script where I can get the current values for the parent option and the child option in a cascading select list.
I have a custom field Impact and Urgency of cascading select type and the field priority. I need to set the priority based on the selected impact and urgency.
This is what I've been trying to do so far. But unfortunately this does not work for me.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager
import com.atlassian.jira.issue.priority.Priority
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
def issue = event.getIssue();
//Issue issue = event.issue
MutableIssue mutableIssue = (MutableIssue) issue;
def priorityManager = ComponentAccessor.getComponent(PriorityManager)
def optionsManager = ComponentAccessor.getOptionsManager()
//CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//CustomField cf = customFieldManager.getCustomFieldObjectByName("Impact and Urgency")
CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impact and Urgency" )
FieldConfig config = cf.getRelevantConfig(issue)
def options = optionsManager.getOptions(config)
def parentOption = options.find {it.value == "test"}
def childOption = parentOption?.childOptions?.find{it.value == "Core Services"}
def childOption2 = parentOption?.childOptions?.find{it.value == "Non-Core Services"}
def childOption3 = parentOption?.childOptions?.find{it.value == "Other Support Services"}
def parentOption1 = options.find {it.value == "VIP user/ Small group/ Department"}
def parentOption2 = options.find {it.value == "One user"}
if (parentOption== "test" && childOption=="Core Services")
{
mutableIssue.setPriorityId("1")
}
else if (parentOption== "test" && childOption=="Non-Core Services"){
mutableIssue.setPriorityId("10200")
}
else if (parentOption== "test" && childOption=="Other Support Services"){
mutableIssue.setPriorityId("10201")
}
else if (parentOption1== "VIP user/ Small group/ Department" && childOption=="Core Services") {
mutableIssue.setPriorityId("10201")
}
else if (parentOption1== "VIP user/ Small group/ Department" && childOption=="Other Support Services") {
mutableIssue.setPriorityId("10202")
}
else if (parentOption1== "VIP user/ Small group/ Department" && childOption=="Non-Core Services") {
mutableIssue.setPriorityId("10201")
}
else if (parentOption== "One user" && childOption=="Core Services") {
mutableIssue.setPriorityId("10201")
}
else if (parentOption== "One user" && childOption=="Non-Core Services") {
mutableIssue.setPriorityId("10202")
}
else if (parentOption== "One user" && childOption=="Other Support Services") {
mutableIssue.setPriorityId("10203")
}
Can anyone help me with this?
Thanks,
Khushbu
You can get value from a cascading select like this:
import com.atlassian.jira.component.ComponentAccessor
ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("custom field name")
// parent value
log.error(((Map<String, String>) issue.getCustomFieldValue(cf)).get(null))
// child value
log.error(((Map<String, String>) issue.getCustomFieldValue(cf)).get("1"))
Hello,
I want to use behaviour in order to set the Priority field based on the selected values of a cascading field type.
Is it possible to do so? Do you have a script for that?
Thanks,
Khushbu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, there.
I've used a Custom SIL Field (see POWER CUSTOM FIELDS free plugin) to create a simple script for the exact case you're describing, set Priority value based on the inputs Impact and Urgency.
I've used yet another custom field also for the priority but of course you could use the system field. It is as simple as this:
string Impact = customfield_XXXXX; string Urgency = customfield_XXXXX; string Priority = "";
// Both Impact and Urgency are requested on issue creation.
// High, Medium or Low are the avaliable options. Check definition of each sccenario. if (Impact == "High") { if (Urgency == "High") { Priority = "Critical"; } else { Priority = "Mayor"; } } if (Impact == "Medium") { if (Urgency == "High") { Priority = "Critical"; } else { Priority = "Mayor"; } } if (Impact == "Low") { if (Urgency == "Low") { Priority = "Minor"; } else { Priority = "Mayor"; } } return Priority;
I hope it helps. It's not too fancy but it gets the job done.
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.