Hello
I'm trying to make the systeme field Description mandatory when a certain custom field get a specific value. If not the case then not
The custom field name is "A catégoriser"
Here is the script I did
Hi @Ulrich Kone
After going through the sample code that you have shared, I can confirm that the approach you are taking is incorrect.
To proceed, please confirm what Behaviour configuration you are using for this. Is it a Server-Side Behaviour or the Initialiser? If it is the former, i.e. Server-Side Behaviour for the Single-Select List, then it is the correct approach. However, if it is the latter, the approach is wrong.
From your code, I assume you are trying to use a Server-Side Behaviour for the Single-Select List, whereby the Description field is set to mandatory based on the option selected on the Single-Select List.
For this to work, you must make a couple of corrections. Firstly, your approach to declaring the Single-Select list is incorrect. Instead of declaring it as:-
def CustomField = getFieldById('customFieldId=11200')
Instead, you must declare it as:-
def CustomField = getFieldById(fieldChanged)
You must use the fieldChanged value to ensure that the Behaviour will only trigger when the change has been made to the Single-Select List. Otherwise, the Behaviour will not work correctly.
Next, your declaration of the Description field is also incorrect. In your code, you have declared it as:-
def desc = getFieldByName('description')
This will not work. Using the lowercase d in Description is meant for the Description field's ID, not the name.
Hence, you must declare it as:-
def desc = getFieldById('description')
Below is a fully working code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def sampleList = getFieldById(fieldChanged)
def sampleListValue = sampleList.value.toString()
def description = getFieldById('description')
description.required = false
if (sampleListValue == 'Option1') {
description.required = true
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Server-Side Behaviour configuration:-
I am also including a couple of test screenshots for your reference:-
1. When the Create dialog first loads and no option has been selected from the Single-Select List as expected, the Description field is not set to mandatory as shown in the screenshot below:-
2. If Option1 is selected from the Single-Select List, as expected, the Description field is set to required as shown in the screenshot below:-
3. If any other option aside from Option1 is selected, the Description field will not be set to required as shown in the screenshots below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Hi @Ulrich Kone
Has your question been answered? If yes, kindly accept the solution provided.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Ram Kumar Aravindakshan _Adaptavist_
Thanks for your asnwer and sorry for the delay
I tried the solution but it seems to not work
Maybe I forgot something
I am inclunding the screenshots
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.
Hello @Ram Kumar Aravindakshan _Adaptavist_
Thank you very much
It works properly (I had a quote in my custom field Value)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.