I need to take values from a multiselect field, convert them to an assigned value, then add them to a text field in comma separated form. Is this possible?
I currently can take a single select field, convert it, then send to a text field.
Hi, so you are doing this with ScriptRunner, right? Is it ok to share the script you've got so far?
import com.atlassian.jira.component.ComponentAccessorimport groovy.transform.BaseScriptimport com.atlassian.jira.ComponentAccessorimport com.onresolve.jira.groovy.user.FieldBehavioursimport com.onresolve.jira.groovy.user.FormFieldimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.ComponentManagerimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.customfields.manager.OptionsManagerimport com.atlassian.jira.issue.fields.config.FieldConfigImplimport com.atlassian.jira.issue.MutableIssue
@BaseScript FieldBehaviours fieldBehaviours
def optionsManager = ComponentAccessor.getOptionsManager()
// Get the Custom Field Managerdef customFieldManager = ComponentAccessor.getCustomFieldManager()
// Get a pointer to my select list custom fieldsdef selectList1 = getFieldByName("G4 - Systems")def selectList2 = getFieldByName("StatusPage_ID_Text")def textBox1 = getFieldByName("StatusPage_ID_Group")
// Get the value of selectList1def selectList1Val = selectList1.getValue()
// If Select List 1 is set to <G4 - Systems value> "JIRA" then set seletList2 to option ""<component ID>.json"
if ("Other" in selectList1.value){// Set the value to the ID of option "27mr8k9zyp8d.json" but must use value IDselectList2.setFormValue("27mr8k9zyp8d")// textBox1.setFormValue("27mr8k9zyp8d")// Next Value} else if ("Maestro" in selectList1.value){selectList2.setFormValue("nxxj7vnbf0h5")textBox1.setFormValue("nxxj7vnbf0h5")
// Next Value} else if ("Ping Federate" in selectList1.value){selectList2.setFormValue("qdqq66hyb7zg")textBox1.setFormValue("qdqq66hyb7zg")
// Next Value} else if ("VDI" in selectList1.value){selectList2.setFormValue("gtztm9frh6lr")textBox1.setFormValue("gtztm9frh6lr")
//Next Value} else if ("A2Go" in selectList1.value){selectList2.setFormValue("ml4f7y316gwq")textBox1.setFormValue("ml4f7y316gwq")//Next Value} else if ("Allegiantair.com" in selectList1.value){selectList2.setFormValue("41c919qx6ljm")textBox1.setFormValue("41c919qx6ljm")//Next Value} else if ("G4Connect" in selectList1.value){selectList2.setFormValue("f730dzmyygx9")textBox1.setFormValue("f730dzmyygx9")
//Next Value} else if ("JIRA" in selectList1.value){selectList2.setFormValue("yrkk8q3n5cmq")textBox1.setFormValue("yrkk8q3n5cmq")
//Next Value} else if ("Crew Bidding Interface (CBI)" in selectList1.value){selectList2.setFormValue("1pxk0h42n6ry")textBox1.setFormValue("1pxk0h42n6ry")
//Next Value} else if ("University" in selectList1.value){selectList2.setFormValue("3vpr2l693bxl")textBox1.setFormValue("3vpr2l693bxl")//Next Value} else if ("Alchemy" in selectList1.value){selectList2.setFormValue("4xh0fm8vxxl6")textBox1.setFormValue("4xh0fm8vxxl6")//Next Value} else if ("Teesnap" in selectList1.value){selectList2.setFormValue("7kcfqs8f7zpc")textBox1.setFormValue("7kcfqs8f7zpc")//Next Value} else if ("Tableau" in selectList1.value){selectList2.setFormValue("9gg9shn8gncd")textBox1.setFormValue("9gg9shn8gncd")//Next Value} else if ("airSMS (Q-Pulse)" in selectList1.value){selectList2.setFormValue("jw879g23jchj")textBox1.setFormValue("jw879g23jchj")//Next Value} else if ("G4Plus" in selectList1.value){selectList2.setFormValue("mpkgzp3s2x7d")textBox1.setFormValue("mpkgzp3s2x7d")//Next Value} else if ("PubWeb" in selectList1.value){selectList2.setFormValue("n0z2qksf0jvd")textBox1.setFormValue("n0z2qksf0jvd")//Next Value} else if ("SharePoint" in selectList1.value){selectList2.setFormValue("qxll2nt9dtb5")textBox1.setFormValue("qxll2nt9dtb5")//Next Value} else if ("Confluence" in selectList1.value){selectList2.setFormValue("rtbw4hj8hlk1")textBox1.setFormValue("rtbw4hj8hlk1")//Next Value} else if ("Wireless Network" in selectList1.value){selectList2.setFormValue("v6v56ggmqxrm")textBox1.setFormValue("v6v56ggmqxrm")//Next Value} else if ("Network Printer" in selectList1.value){selectList2.setFormValue("yv70n7m7d3mp")textBox1.setFormValue("yv70n7m7d3mp")//Next Value} else if ("Network Folder" in selectList1.value){selectList2.setFormValue("yvyys1b9ldr9")textBox1.setFormValue("yvyys1b9ldr9")
//Next Value} else if ("AIS" in selectList1.value){selectList2.setFormValue("zzjct3fsrrss")textBox1.setFormValue("zzjct3fsrrss")
//All other selections} else {selectList2.setFormValue(null)selectList2.setReadOnly(false)}
I now can get all the values into the text field, but I need to convert them to a specific mapping. You can see the "C#" definitions in my code. Each C# is an actual value in the "selectList1" field and the mapping should go into the text field instead of the actual value within the multiselect field. I have updated my script to the following:
import com.atlassian.jira.component.ComponentAccessorimport groovy.transform.BaseScriptimport com.atlassian.jira.ComponentAccessorimport com.onresolve.jira.groovy.user.FieldBehavioursimport com.onresolve.jira.groovy.user.FormFieldimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.ComponentManagerimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.issue.customfields.manager.OptionsManagerimport com.atlassian.jira.issue.fields.config.FieldConfigImplimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.core.util.StringUtils@BaseScript FieldBehaviours fieldBehavioursdef optionsManager = ComponentAccessor.getOptionsManager()// Get the Custom Field Managerdef customFieldManager = ComponentAccessor.getCustomFieldManager()// Get a pointer to my select list custom fieldsdef selectList1 = getFieldByName("G4 - Systems")def selectList2 = getFieldByName("StatusPage_ID_Text")// Set List of Component IDsdef C1 = "27mr8k9zyp8d"def C2 = "nxxj7vnbf0h5"def C3 = "qdqq66hyb7zg"def C4 = "gtztm9frh6lr"def C5 = "ml4f7y316gwq"def C6 = "41c919qx6ljm"def C7 = "f730dzmyygx9"def C8 = "yrkk8q3n5cmq"def C9 = "1pxk0h42n6ry"def C10 = "3vpr2l693bxl"def C11 = "4xh0fm8vxxl6"def C12 = "7kcfqs8f7zpc" def C13 = "9gg9shn8gncd" def C14 = "jw879g23jchj" def C15 = "mpkgzp3s2x7d" def C16 = "n0z2qksf0jvd"def C17 = "qxll2nt9dtb5"def C18 = "rtbw4hj8hlk1"def C19 = "v6v56ggmqxrm"def C20 = "yv70n7m7d3mp"def C21 = "yvyys1b9ldr9" def C22 = "zzjct3fsrrss"// Get the value of selectList1def selectList1Val = selectList1.getValue()if (selectList1 != null){selectList2.setFormValue(selectList1.getValue())selectList2.setReadOnly(true)}//All other selections else{selectList2.setReadOnly(false)selectList2.setHidden(false)}
It looks like you're new here. Sign in or register to get started.