Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to clear value of the custom selection field when the user selects another custom selection fiel

Komal Parate March 11, 2021

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:

image1.PNG

Img1: The specify dropdown created with dropdown value computer IP and computer hostname

image2.PNG

Img2: Error message for invalid hostname

image3.PNG

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.

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Mario
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 11, 2021

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

Komal Parate March 17, 2021

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events