Dear Community
I have a request model with 3 multiple checkboxes.
Before request is raised, I need to perform a check to make sure that user make appropriate selection.
- If user select an App without Citrix then the checkbox concerning Apps with Citrix and the one with Citrix overall or specific should be set to N/A
- If user select one or several Apps with Citrix, then Apps without Citrix should be set to N/A
- If user select All Apps with Citrix are affected then App 4 to 7 should be selected and apps without Citrix should be set to N/A
- If user select Only specific Apps with Citrix are affected then, apps without Citrix should be set to N/A, Apps with Citrix N/A should not be selected and at least one App from App 4 to 7 should be selected
I though I can do that using Groovy validator but was unable to set it up (lack of knowledge as I'm not experienced with JIRA)
I set all the 3 custom fields as mandatory (that's why each of them got a N/A)
Thanks in advance for your help
Philippe
Hey @Philippe Beltran and welcome to the community,
For this (something like dynamic changes on a form) you might want to look in to an app called Scriptrunner and their concept of Behaviours
https://docs.adaptavist.com/sr4js/latest/features/behaviours
This will allow you to change the options on those boxes based on other (selected or not selected) options on the form.
Hi Dirk
Thank you for the information but I cannot find behaviours in my JIRA.
In fact I do not have Add-ons listed
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.
Hi Dirk
Now I have Scriptrunner but I don't know how to implement the code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Philippe Beltran ,
Have you gone through the documentation on Behaviours?
https://docs.adaptavist.com/sr4js/latest/features/behaviours
https://docs.adaptavist.com/sr4js/latest/features/behaviours/api-quick-reference
So from your screenshot(s) it shows as 3 custom field.
So you will have to write a simple if/then statement in the idea of first getting the value of your 1st custom field and based on what that is you can do a set on the other custom fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dirk
Thank you for the information but here are my points:
- most of the codes I found are structure as follow:
several import commands
example: import com.atlassian.jira.issue.customfields.option.Option)
Then def commands (example: def updateCustomFieldValue(issue, String fieldName, String newValue, user))
and finally test commands like if, etc...
I was not able to find detailed explanations about what is necessary to create a code, also unable to find details about syntax)
I would like my code to act when user select one or multiple options from a checkbox (example: if he select App1 then checkbox Apps with Citrix should automatically be set to N/A)
Any further help will really be appreciated
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Philippe Beltran ,
The "most codes" you mention are more used in Post functions, what you want (from your requirement) is a behaviour.
without actually rebuilding your form I'm not really able to provide exact code.
A behaviour can be build with a lot less code especially if you are just trying to manipulate the fields that are on the form. The documentation I mentioned contains a lot of examples but you'll have to first build the behaviour itself and then add the code to it.
For a on the fly behaviour (so not a post function) you can use code such as setFieldValue() and don't need to use the updateCustomFieldValue()
def customfield_citrixapp = getFieldById(getFieldChanged()) //this will be the field that was adapted
String customfield_citrixapp_value = customfield_citrixapp.getValue()
def cfcustomfieldtoChange = getFieldById("customfield_xxx")
if (customfield_citrixapp_value == "somevalue"){
cfcustomfieldtochange.setFormValue("the value you need")
}else{
}
Depending of course on the field type/value you need to check on,.... this code will change
I suggest you first read up on behaviours itself and then dive in to code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From the procedure point of view
I create a behaviours
I added a mapping to the ticket type I wanted the behaviour to be linked with
I added all 3 customs fields
I adjusted the code with the custom filed name and added that to to first field using Add Server-side script
See attachment
The I tried to create a ticket and selected the value "Tiamo" in the first checkbox, if code is working I should have value of second checkbox be set to N/A. Unfortunately, nothing happen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Once thing you can change already is to use "customfield_10903" instead of just 10903
Secondly, you don't need to add all the fields involved in the behaviour, just the field that wil trigger the behaviour (so the first one). Changing that field will then trigger the script.
But I'll look in to creating an example case for you on my instance so you have a working code example, that might be easier.
I'll get back to you as soon as possible.
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.
Hey @Philippe Beltran ,
I've played a bit with a code example and for me this should work for you (with the correct adaptations of course.
1) I've created a new request form with 2 checklists
2) Then I created a new Behaviour mapped to the Request Type, added the List 1 field and added a script to that.
3) The script is below (and I added some comments).
import com.atlassian.jira.component.ComponentAccessor
def list1Field = getFieldById(getFieldChanged()) //list 1 formfield
def list1FieldValue = list1Field.getValue() //list 1 formfield value (to compare later)
def list2Field = getFieldById("customfield_11602") //list 2 formfield to change
def list2FieldObject = customFieldManager.getCustomFieldObject("customfield_11602") //custom field object to read the options from
def config = list2FieldObject.getRelevantConfig(getIssueContext())
def optionsManager = ComponentAccessor.getOptionsManager()
def options = optionsManager.getOptions(config)
if(list1FieldValue == "App 1"){
def optionsToSelect = options.findAll { it.value == "N/A" }
list2Field.setFormValue(optionsToSelect*.optionId)
}
This will essentially
What we end up with is:
Most of the code comes from (or is derived from) https://docs.adaptavist.com/sr4js/latest/features/behaviours/behaviours-examples/setting-field-defaults
It's still code so I can help you understand it a bit more but you will need to get a grasp of what's going on :)
Hope this helps you a bit further now!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much. After I adjusted your code and made the right mapping it works well.
Now I have to add all the possibilities with also automatic checkbox clearing in case nothing is selected in the first list.
Thank you very much!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome!
Yeah, you'll have to bring in your own logic to the behaviour but at least now you have the building blocks to do so :)
If you get stuck anywhere we're always here to help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To setup the second checkbox should I create a new behaviour or can I do it in same by adding the field and making the coding there?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'd stick to the one behavior when possible. You can indeed just add the field there and add the extra code.
Imho, a behavior will stretch a certain issue type/request type(s) and if the code works for all those you can just add the fields that might trigger it and add the additional code :)
Will also make it a lot easier for maintaining.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Strangely when I adjust the code to add behaviour for the second field it is not working.
I tried to create a second behaviour only for the second field while disabling the first working behaviour, nothing to, it is not working
Any idea what can be the problem?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you share the code of your second behavior? Maybe something is missing/error'ing out.
Sadly these things don't throw a whole lot of errors when executing the code towards the UI. You can always open the logs and see if there is an exception happening there when you trigger the behavior.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
def list4Field = getFieldById(getFieldChanged())
def list4FieldValue = list4Field.getValue()
def list5Field = getFieldById("customfield_10900")
def list5FieldObject = customFieldManager.getCustomFieldObject("customfield_10900")
def config2 = list5FieldObject.getRelevantConfig(getIssueContext())
def optionsManager2 = ComponentAccessor.getOptionsManager()
def options2 = optionsManager2.getOptions(config2)
if(list4FieldValue == "App 4"){
def options2ToSelect = options2.findAll { it.value == "N/A" }
list5Field.setFormValue(options2ToSelect*.optionId)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i don't really see anything wrong at first glance.
Do you see anything in the logs when you trigger the behavior?
Also as a sidenote, you don't need to put a number behind the variables (e.g. config 2) you can just re-use them :)
I feel like logs would help us greatly here.
It could be the wrong custom field, another value than "App 4",..
You could try and removing the if that checks for the value for a moment to see if it triggers then. That would at least verify the rest of the code works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After reloading the customer portal and try again to create a request it works as it should (strange)
Now I'm facing a small problem.
If N/A has been set by a previous selection and user wants to select a value within the same custom fields, N/A stay selected. I'm trying to code that by selecting a value, if N/A was selected due to a previous action, it must be deselected
Something like: if APP 1 is selected but N/A is already selected then deselect N/A
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I need some more help.
I wanted to manage the content of the Description field. I searched and tried multiple codes but none is working, field remains empty
Idea is to adjust Description content based on checkbox selection.
Thanks for your help
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.