Setup:
Two custom fields:
Scenario:
How can you accomplish this with ScriptRunner during a transition screen?
A similar question was asked and answered with a sample working code in this Community Post.
The only difference between the example code provided in the Community Post and your requirement is the values used in the Single Select List field.
I hope this helps to solve your question. :)
Thank you and Kind Regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_ - thank you very much for sharing this. I went through your sample code and modified it but it didn't seem to work for me...
In my case, list1 = Event Classification and list 2 = Event Category
Below is my code modified used:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def list1 = getFieldById(fieldChanged)
def list1Value = list1.value.toString()
def list2 = getFieldByName("Event Category")
def optionManager = ComponentAccessor.optionsManager
def customFieldManager = ComponentAccessor.customFieldManager
def list2CustomField = customFieldManager.getCustomFieldObject(list2.fieldId)
def list2Config = list2CustomField.getRelevantConfig(issueContext)
def list2Options = optionManager.getOptions(list2Config)
def listBNewOptions
if(list1Value == "Incident") {
listBNewOptions = ["1 - Root Level Intrusion (Incident)", "2 - User Level Intrusion (Incident)", "4 - Denial of Service (Incident)", "7 - Malicious Logic (Incident)"]
} else if(list1Value == "Event") {
listBNewOptions = ["3 - Unsuccesful Activity Attempt (Event)", "5 - Non-Compliance Activity (Event)", "6 - Reconnaissance (Event)", "8 - Investigating (Event)", "9 - Explained Anomaly (Event)"]
} else {
listBNewOptions = ["1 - Root Level Intrusion (Incident)", "2 - User Level Intrusion (Incident)", "4 - Denial of Service (Incident)", "7 - Malicious Logic (Incident)", "3 - Unsuccesful Activity Attempt (Event)", "5 - Non-Compliance Activity (Event)", "6 - Reconnaissance (Event)", "8 - Investigating (Event)", "9 - Explained Anomaly (Event)"]
}
def listBNewOptionsMap = [null: "None"]
listBNewOptionsMap += list2Options?.findAll {
it.value in listBNewOptions
}?.collectEntries {
[ (it.optionId.toString()) : it.value ]
}
list2.setFieldOptions(listBNewOptionsMap)
I am curious about this following line in your code as you pointed out in your example:
def list1 = getFieldById(fieldChanged)
def list1Value = list1.value.toString()
How does this tell ScriptRunner that list1 = Event Classification?
When I tried to replace it with the following, I started getting error:
def list1 = getFieldByname("Event Classification")
def list1Value = list1.value.toString()
Would you be able to provide more insight? Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The fieldChanged option is used to ensures that the Behaviour is triggered when any change is made to the Field the Server-Side Behaviour is configured for.
If you observe the print screen in the Community Post, as shown below, you will notice the Server-Side Behaviour has been configured for the field List 1.
That is why, in the code, to invoke the List 1 fieldChanged is used, i.e.:-
def list1 = getFieldById(fieldChanged)
Could you provide a print screen of your Behaviour configuration along with a print screen of the create or edit screen where these fields are used?
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_- thank you so much for pointing that out - sorry I'm still very much a newbie with ScriptRunner.
I put my code as an initializer instead of a server-side script. I deleted the initializer, created a server-side script while picking Event Classification as the field and it worked like a charm... THank you so much!
If you don't mind, I have another open question that I can use some hint on if you could so kind so shed some light (https://community.atlassian.com/t5/Jira-questions/ScriptRunner-How-To-Restrict-Issue-Type-Creation-By-Groups/qaq-p/1804874#M499634). Thank you Ram!!
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.