Jira version: 8.13
JIRA service management :4.13.3
Scriptrunner version: 6.19.0
Hi,
We are using the Script runner plugin via the Behaviours to show/hide fields based on the selected value.
Scenario:
1)On the create screen I have a "specify" single select box (dropdown) where there are two dropdown values mentioned "computer IP" and "computer hostname".
2)If any customer selects computer IP it auto populates computer IP dropdown on the create screen and the computer hostname is hidden and when the user selects computer hostname the computer IP is hidden and all the fields are required fields.
3) When the user specifies the computer IP by selecting the dropdown, I need to clear the value of the hostname and vice -versa in the create screen.
4) As it is capturing both the values IP/Hostname entered by the customer. Is there any function to clear the value of the text field so that it does not appear into the view screen?
I am using the below script for hiding the fields.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def Computer_IP = getFieldById("customfield_13500")
def Computer_Hostname = getFieldById("customfield_13601")
def Specify = getFieldById("customfield_13603")
String opt = "Computer IP Address"
String Host = "Computer Hostname"
if (getFieldById(getFieldChanged()).clearError().getValue()==opt.trim()){
Computer_IP.setHidden(false).clearError()
Computer_IP.setRequired(true).clearError()
Computer_Hostname.setHidden(true).clearError()
Computer_Hostname.setRequired(false).clearError()
}
else if (getFieldById(getFieldChanged()).clearError().getValue()==Host.trim()){
Computer_Hostname.setHidden(false).clearError()
Computer_Hostname.setRequired(true).clearError()
Computer_IP.setHidden(true).clearError()
Computer_IP.setRequired(false).clearError()
}
In UI it appears as below:
Img1: The specify dropdown created with dropdown value computer IP and computer hostname
Img2: Error message for invalid hostname
Img3: View screen of the ticket created with both custom field’s hostname and IP. Need to display any one of the custom fields selected by the customer on the view screen.
Hey Kormal Pate and welcomoe to the community.
Good question and thank you for showing your code.
The function setFormValue(value)(https://scriptrunner.adaptavist.com/latest/jira/behaviours-api-quickref.html#_formfield_setformvalue_value) should be the method your searching after.
If you want to clear the hostname you most likely can insert your logic
Computer_Hostname.setFormValue("")
to clear the text field by setting it to an empty string.
Hope that helps:)
Regards Mario
Hello Mario,
Thank you for your quick response tried using the function setFormValue(value)
and edited my code now it is working as expected.
Regards,
Komal Parate
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.