Hello Community,
there are 2 issue types and custom field is finance service with drop down values (ABC,DEF,GHI,JKL,MNO,PQR,STU,VWX, YZ)
Issue type - IRB1
Issue type -IRB2
now, what i need is - while creating a ticket, user select issue type - IRB1 then in finance service list to appear ABC,DEF,GHI,JKL,MNO) end rest for other issue type IRB2 when user create a ticket.
how to plot this ussing script runner behavior?
Hi @Manoj
For your requirement, you will need to use ScriptRunner's Behaviour Initialiser.
Below is a sample working code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def sampleList = getFieldByName('Sample List')
def project = issueContext.projectObject
def options = []
if (project.key == 'MOCK') {
options = ['Option 1', 'Option 2']
} else if (project.key == 'ST') {
options = ['Option 3', 'Option 4']
}
sampleList.setFieldOptions(options)
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Behaviour configuration:-
If you observe the screenshot above, the Behaviour is configured for two projects, i.e. Mock and Sample Test.
In the Initialiser section, the conditions are added to determine what value will be set to the list's option when the project is changed.
So in this example, if the project is MOCK, the list will display options Option 1 and Option 2, and if the project is Sample Test (ST), the list will display options Option 3 and Option 4.
Below are a couple of test screenshots for your reference:-
1) If the project is MOCK, the Sample List will be filtered to Option 1 and Option as shown below:-
2) If the Project is Service Test, the sample List will be filtered to Option 3 and Option 4, as shown below:-
I hope this help to solve your question. :-)
Thank you and Kind regards,
Ram
@Ram Kumar Aravindakshan _Adaptavist_
Hello Ram, thanks a lot for investing your efforts and replying back to me on query.
as you have mentioned above - So in this example, if the project is MOCK, the list will display options Option 1 and Option 2, and if the project is Sample Test (ST), the list will display options Option 3 and Option 4.
however i have 2 issuetypes in my project and custom field finance service.
I have just tried the code replacing the fields in my jira environment, though it is not throwing error but it is not working at all.
============================================the script i am trying to run is below:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Manoj
If you want to do it with different issue types instead of different projects, the approach is pretty much the same.
You will need to modify the code to something like:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def sampleList = getFieldByName('Sample List')
def issueType = issueContext.issueType.name
def options = []
if (issueType == 'Bug') {
options = ['Option 1', 'Option 2']
} else if (issueType == 'Story') {
options = ['Option 3', 'Option 4']
}
sampleList.setFieldOptions(options)
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
After going through your code, I have one question, are you sure that the name of the Single Select List is financeservice, i.e. all in lowercase without any spacing?
Could you please share a screenshot of the field from the Custom Fields section?
Below is an updated screenshot of the configuration for your reference:-
Below are a couple of test screenshots for your reference:-
1) If the issue type is a Bug, only Option 1 and Option 2 are displayed.
2) If the issue type is Story only Option 3 and Option 4 are displayed.
I hope this helps to answer your question. :-)
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_
Hi, sharing below screen shot for reference, I did check on finance service, it has space between finance & service and i have maintain the same while writing the script.
pls see the screnshot and 1 important thing these 2 issue has different workflow.
Do i need write separate code for the same.? kindly suggest.
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_ Hello again,
i have observe the script shared by you again, carefully indeed and got to know what i was missing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Manoj
Great to hear the solution worked for you. 😀
Please accept the answer.
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_ Hello Gm,
yes I accepted the answer.
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
I am unable to understand above script lines, is this something like we have class or library in Atlassian which keeps recorded script and from there we pull the relative one and use.
Could you pls help to know about this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Manoj
So the BaseScript class is a standard annotation from the Groovy API. Where as the FieldBehaviour class is from ScriptRunner. It is used to be able to access the Behaviour methods from any editor.
By default, when you use the Inline Behaviour editor, this is not required as these functions are already inbuilt. However, if you use ScriptRunner's Editor, you will need to include this to be able to invoke the Behaviour methods.
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.
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_ Hi, Now i am trying to create similar process for custom field.
custom field is Pillar and another custom field is Platform, so based on pillar values only values relevant to that pillar will appear and platform.
Instead of issue type i want to use custom field.
def issueType = issueContext.issueType.name
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.
Hi @Manoj
If you want to take a value from a custom field, you cannot use the Initialiser anymore.
You will need to create a Server-Side Behaviour for that field, and your Server-Side Behaviour code will be something like this:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@@BaseScriptFieldBehaviours behaviours
def sampleList = getFieldById(fieldChanged)
def sampleListValue = sampleList.value as String
def sampleText = getFieldByName('Sample Text')
if (sampleListValue == 'Option 1') {
sampleText.setFormValue('Test 1')
} else if (sampleListValue = 'Option 2') {
sampleText.setFormValue('Test 2')
}
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
For more information on configuring a Server-Side Behaviour, I suggest going through this ScriptRunner Documentation.
I hope this helps to answer your question. :-)
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_ Thanks, so samplelist in your code would be Pillar or platform? I tried replacing fields name but no luck.
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.
@Ram Kumar Aravindakshan _Adaptavist_ These are custom fields DropDown Values
Pillar has 5 Values - Such department like HR, Marketing, IT, Sales and Others.
Platforms has more than 20 values such sub-departments as HR_Recruitmen, HR_TA etc etc.
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.
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_ To me more specific , what i want to achieve is when I select HR Department in Pillar Field (custom field) and then it only shows the sub-department in platforms custom field.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
H @Manoj
From your latest comment, it appears that you want to use one list to filter the options of a second list field. Is this correct? If yes, then this is a pretty common question.
There are a couple of Community questions already answered for this. For example, this Community Post
Below is an example working code for your reference:-
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def products = getFieldById(fieldChanged)
def productsValue = products.value.toString()
def available= getFieldByName("Available Options")
def customFieldManager = ComponentAccessor.customFieldManager
def optionManager = ComponentAccessor.optionsManager
def list1CustomField = customFieldManager.getCustomFieldObject(available.fieldId)
def availableConfig = list1CustomField.getRelevantConfig(issueContext)
def list1Options = optionManager.getOptions(availableConfig)
def availableOptions = []
if(productsValue == "Samsung") {
availableOptions = ["TV","Mobile Phone", "Charger", "Laptop", "Memory Cards", "SSD", "Tablet"]
} else if(productsValue in ["Sony","Apple"] ) {
availableOptions = ["TV","Mobile Phone", "Charger", "Laptop"]
}
def availableOptionsMap = list1Options?.findAll {
it.value in availableOptions
}?.collectEntries {
[ (it.optionId.toString()) : it.value ]
}
available.setFieldOptions(availableOptionsMap)
I hope this helps to answer your question. :-)
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_ Thanks for replying back, yes its correct "one list to filter the options of a second list field".
should i replace products (in your script) with pillar (in my script) as per my requirement?
Here I have pillar and P&S platforms, so basis on value selected in pillar, P&S platforms show the list of values relevant to value/text selected in pillar.
kindly suggest.
Thanks!
M
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.