Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Make description field mandatory based on select list custom field

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

 

import com.atlassian.jira.issue.fields.DescriptionSystemField
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

//Apply Scriptrunner behaviour on select list field

def CustomField = getFieldById('customFieldId=11200') //select list field
def desc = getFieldByName('description') //multi-line text field

log.debug('customFieldId=11200' + CustomField.getValue())

if(CustomField.getValue() == "A catégoriser") {
   DescriptionSystemField.setRequired(true)
} else {
    DescriptionSystemField.setRequired(false)
}
But the script failed
Can somebody help me in that?
Best regards

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 16, 2023 • edited

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

behaviour_config.png

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

test1.png

 

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

test2.png

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

test3.png

test4.png

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

Thank you and Kind regards,

Ram

 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 20, 2023

Hi @Ulrich Kone

Has your question been answered?  If yes, kindly accept the solution provided.

Thank you and Kind regards,

Ram

 

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

Hello @Ram Kumar Aravindakshan _Adaptavist_ 

Thank you very much

It works properly (I had a quote in my custom field Value)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events