Hi,
I'm looking for a solution which would let me to clear custom fields value when I edit and select anoher custom field value.
For example, I have a Radio buttons field named Run Impacts. Possible values are : No/positive/negative.
If I first select positive or negative, some other custom fields (A, B, C let's say) needed to be completed display (via behaviours plugin). But if I edit the value and finally select "No", I would need that the value of all the A, B, C fields be cleared.
I think I should create a custom script listener but i don't know how to build the script.
Any ideas?
Thanks for your help
Melissa
Hi Melissa,
You can add a listener, as you described admin > script Listeners > Custom Listener, assign the project / projects you want and for the events you should select Issue Updated (therefore every time there is a change at the radio button custom field the listener will get triggered). For inline script copy / paste the script below
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.customfields.option.LazyLoadedOption import com.atlassian.jira.issue.util.DefaultIssueChangeHolder Issue issue = event.issue def customFieldManager = ComponentAccessor.getCustomFieldManager() def customField2 = customFieldManager.getCustomFieldObjectByName("radioBtn") LazyLoadedOption radioBtnOption = (LazyLoadedOption) issue.getCustomFieldValue(customField2) def changeHolder = new DefaultIssueChangeHolder(); def customField4 = customFieldManager.getCustomFieldObjects(issue).find {it.name == "textfield"} if (radioBtnOption?.getValue() == "No") { customField4.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField4), ""),changeHolder) }
What it does: If the value of the custom field "radioBtn" is "No" then it updates the value of the custom field with name "textfield" with an empty string. This applies only for text custom fields. Hope that helps.
Edit: Now with Kristian's script you have two options. Via a behaviour or a Listener. Choose which suits your needs.
Kind regards
Hi Mel,
You can do this with Behaviours. I have enclosed a sample script below which checks the value in Radio Button A and when option 1 is selected clears the value in Radio Button B.
Note that by default JIRA excludes the none option from the options map so we have to include this before we can set the value to no value selected (none).
The documentation here shows example code of how you could set a radio button option if required.
// Get the custom fields by Name def radioA = getFieldByName("Radio A") def radioB = getFieldByName("Radio B") // get the value of Radio A String radioAVal = radioA.getValue() //Define the option for none as Jira does not include this in the radio fields map by default Map radioBFieldOptions = [:] radioBFieldOptions.put ("-1", "None") // If the value selected in Radio Button A is 1 if (radioAVal == "1") { // Set Radio Button B to None to clear its value radioB.setFormValue(-1) }
I hope this helps
Thanks
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could action this with a script as a post-function action if the changes are only going to be made during transitions. But if it could be altered using the edit functionality you do indeed need to use a listener.
One option for you is to use ScriptRunner and you may want to review the documentation at https://scriptrunner.adaptavist.com/latest/jira/listeners.html for how listeners work and https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html for an example of how to set issue attributes.
Hope this helps.
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.