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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set required custom field when selecting option in multi select custom fieldlist

Hi everyone,

I want to create behavior that makes a custom field required when the user selects a specific option in the multi select field.

For example : 

"Deployment Platform" - it's a multi select list custom field

"Impact" - Free text custom field  

Scenario:

I want that when a user selects in the "Deployment Platform" the option "Mobile",

The "Impact" custom field will be required.

 

Thanks

1 answer

0 votes
Fadoua Community Leader Feb 11, 2021

@Zachi Meyer 

Since you mentioned behaviour, I assume you have the adaptavist ScriptRunner. If yes I can send you the script.

Please confirm 

Best,

Fadoua

@Fadoua   yes, I have script runner

Fadoua Community Leader Feb 11, 2021

@Zachi Meyer 

Go to the behaviour screen, add the "Deployment Platform" field then click add script:

def deploymentPlatform = getFieldByName("Deployment Platform")

def impact = getFieldByName("Impact")

 

def impactOption = deploymentPlatform.getValue()

If (impactOption == "Mobile"){

  impact.setRequired(true)

}

Else if (impactOption == "xxxx"){

  impact.setRequired(false)

}

 

Make sure to add Else if for all the other options and set them to false otherwise you will get some unexpected behaviour.

Let me know if you have any questions,

Best,

Fadoua

Hi @Fadoua  ,

 

Can I do

 

 Else if (impactOption != "xxxx") ?
Fadoua Community Leader Feb 15, 2021

@Zachi Meyer  Behaviours are little bit different than regular programming, you have to enter each option otherwise I noticed some weird behaviour when I go between options.

There is nothing wrong with trying the code you sent me, however you try to move between the options and see if it is behaving the way you want.

Best,

Fadoua

@Fadoua  the code you gave me and the "Else if" I tried didn't work. The impact field wasn't appeared as required.

I use multi select list, for example:

 

Multi Select.JPG

Fadoua Community Leader Feb 15, 2021

@Zachi Meyer did you add the deployment pattern field to the behaviour? The code should be added to the deployment pattern field because based on the choice there the impact option will be set to required.

Please confirm.

Best,

Fadoua

@Fadoua  By deployment pattern you mean deployment platform field?

I copied you're code and added the other options in the "impactOption" and it didn't work.

Fadoua Community Leader Feb 16, 2021

@Zachi Meyer  Yes Add the deployment platform field to the behaviour? then add the script under the deployment platform field.

Can you please send a screenshot once you hide any sensitive info?

Best,

Fadoua

@Fadoua Yes I add deployment platform field to the behaviour.

I also add mapping.

 

Behaviour STG.jpg

Fadoua Community Leader Feb 17, 2021

@Zachi Meyer  Can you please switch off the use validator plugin?

Also I know my question will sound silly but did you make sure that both fields exist on the screen?

Best,

Fadoua

@Fadoua  I switched off the validator but it still didn't work.

Both fields appears on the same screen (Please see the screenshot):

Deployment Platform screen.jpg

Fadoua Community Leader Feb 17, 2021

@Zachi Meyer 

def deploymentPlatform = getFieldByName("Deployment Platform")

def impactAnalysis = getFieldByName("Impact Analysis")

 

def impactAnalysisOption = deploymentPlatform.getValue()

If (impactAnalysisOption == "Mobile"){

  impactAnalysis.setRequired(true)

}

Else if (impactAnalysisOption == "xxxx"){

  impactAnalysis.setRequired(false)

}

Please update the field to reflect "Impact Analysis"

I am seeing it as the issue otherwise I will ping someone from Adaptavist here

@Fadoua  it's OK . I replaced it before to "impact analysis" and it didn't work either :(

Fadoua Community Leader Feb 17, 2021

@Kristian Walker _Adaptavist_  your help is needed here please, I am not sure what am I missing that the script is not working as expected.

Thank you!

Best,

Fadoua

Fadoua Community Leader Feb 17, 2021

@Zachi Meyer  Let's see if Kristian can help as he/she works for Adaptavist

Hi Fadouha,

Please note that I will help as best as I can but I am not an expert on ScriptRunner for Jira Server.

However, I can confirm when using Select list fields you need to get the value out of the *List* data structure to compare to in your script and I can confirm we have an example located here which shows how to do an operation when a value is selected in a checkbox field which is similar to your requirement and you will be to take this script and use it as a reference guide to help create the script that you require.

If you require assistance with this, then I would advise raising a support ticket for this through our support portal located here so that someone in the ScriptRunner for Jira Server support team can assist yourself with this.

Regards,

Kristian

Fadoua Community Leader Feb 18, 2021

@Kristian Walker _Adaptavist_  thank you very much for your quick assistance! I totally missed the tabs.

@Zachi Meyer Any luck?

@Fadoua  @Kristian Walker _Adaptavist_ Thanks you for assistance.

I didn't have time today to deal with it. I will update you If it will work soon :)

Fadoua Community Leader Feb 18, 2021

@Zachi Meyer I will try as well later tonight.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

4,561 views 12 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you