Forums

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

Scriptrunner Server Side script is not working for field in second tab.

Chaya June 7, 2023

I have multiple tabs for Bugs. When I tried to create a scriptrunner server side script, it works fine for all the fields in the first tab. But same kind of server side script not working for field in the second tab. I have two tabs, Reporting Fields and Second is Development Fields in Jira. I use Jira Software 8.21.0 and Scriptrunner 7.5.0.

multiple_tabs.PNG      

For the dropdown field inside the reporting fields tab, below server side script is working:

 

def customField = getFieldById(fieldChanged)
def customFieldValue = customField.value
if(customFieldValue == "xyz"){
    customField.setError("Invalid Value")
}else{
    customField.clearError()
}
But same script does not work for Development Fields tab which is second tab.

1 answer

3 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
June 8, 2023

Hi @Chaya

Could you please clarify what version of Jira and ScriptRunner you are currently using?

I have tried to do a basic test in my environment, but I don't seem to have any issues.

Below is the working sample code that I have tested with:-

def singleSelect = getFieldById(fieldChanged)

def singleSelectValue = singleSelect.value.toString()

def sampleText = getFieldByName('Sample Text Field')

sampleText.setFormValue('')

if (singleSelectValue == 'Option 1') {

sampleText.setFormValue('Option 1 Selected')

} else if (singleSelectValue == 'Option 2') {

sampleText.setFormValue('Option 2 Selected')

}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

behaviour-1.png

In this test case, the Single Select List "Single Select" is added to the first tab. If either Option 1 or Option 2 is selected from the Single Select List, the text field, i.e. Sample Text Field which is set on the 2nd tab will update accordingly.

I have run this test with Jira 9.6.0 and ScriptRunner version 8.4.0.

Below are a couple of test screenshots for your reference:-

1) The Single Select List is added to the first tab, i.e. Field Tab as shown in the screenshot below:-

image1.png

2) When Option 1 is selected from the Single Select List on the first tab as shown below:-

image2.png

3) As expected the text field Sample Text Field is updated to "Option 1 Selected" on the second tab as shown below:-

image3.png

4) When Option 2 is selected from the Single Select List on the first tab as shown below:-

image4.png

5) As expected the text field Sample Text Field is updated to "Option 2 Selected" on the second tab as shown below:-

image5.png

6) When Option 3 is selected from the Single Select List on the first tab as shown below:-

image6.png

7) As expected the text field Sample Text Field is cleared on the second tab as shown below:-

image7.png

I hope this helps to solve your question. :-)

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Chaya June 8, 2023

I use Jira Software 8.21.0 and Scriptrunner 7.5.0.

Instead of your script above, can you try adding any second tab field as a field and then try to add some error whenever it changes. Select Impact field and then add server side script.second_tab_field.PNG

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
June 8, 2023

Hi Chaya,

In your last comment, you mentioned:-

Instead of your script above, can you try adding any second tab field as a field and then try to add some error whenever it changes. Select Impact field and then add server side script.

I don't seem to be encountering any issues, even if I am to set the behaviour for a field residing on the second tab.

Below is the sample code that I have tested with:-

def sampleTextField = getFieldById(fieldChanged)

def sampleTextFieldValue = sampleTextField.value as String

sampleTextField.clearError()

if(sampleTextFieldValue) {

sampleTextField.setError('This field should be empty')

}

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:-

behaviour_config.png

This example behaviour aims to return an error message if any value is entered into the Sample Text Field placed on the second tab.

Looking at the code you have shown in your screenshot, you seem to be setting the error message on the Server-Side Behaviour with no condition to determine when the error message should be displayed. I suspect this is the main problem.

Please refer to the sample code I provided and observe how I have added the if/else condition to determine when the error message should be displayed.

Below are a couple of test screenshots:-

1) If the Sample Text Field has any value, the field's error message is displayed as shown below:-

test1.png

2) If the field is empty, the error message is also removed as shown below:-

test2.png

I hope this helps to answer your question. :-)

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

 

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
June 13, 2023

Hi @Chaya

Has your question been answered?

If yes, please accept the answer.

Thank you and Kind regards,

Ram

Chaya June 13, 2023

hi, it is not working for me for Dropdown field in the second tab. Only first tab fields, script seems to be working.

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
June 13, 2023

Hi @Chaya

Could you please share a screenshot of the tab with the fields that are not working and mark the fields that are currently not working so I can test it in my environment?

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Chaya June 19, 2023

Hi Ram,

I cannot share screenshot because of Data sensitivity. But simple scripts are not working for all the second tab fields.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events