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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,548
Community Members
 
Community Events
184
Community Groups

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

2 answers

1 accepted

Hi @Zachi Meyer ,

Continue from the conversation on your reported ticket. You can use this reference from the Adaptavist library.

This is a sample script I tested on my end manage to work:

import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

// Multi Select List field
def multiSelectField = getFieldByName("Multi1")
// Multi Text Line field
def multiLine1 = getFieldByName('TextMulti1')
// Value for a multi-select field will always be a list even if "None" is selected
def multiSelectFieldValue = multiSelectField.value as List
def multiValue = multiSelectFieldValue.equals("A")
log.warn "=================================> $multiSelectFieldValue"
log.warn "=================================> $multiValue"
def description
// If value is null
if (multiSelectFieldValue == [null]) {
description = 'Multi Select Field is set to None'

// If a given string is selected
} else if (multiSelectFieldValue == ["A"]) {
description = 'Multi Select Field is set to A'
multiLine1.setRequired(true)
log.warn'It entered'
}

 Below is the screenshot:

Screenshot 2021-03-11 at 9.40.25 AM.png

@Amir Mustapha _Adaptavist_  thanks , I'll take a look :)

@Amir Mustapha _Adaptavist_  it works for me too , Thanks!

I removed the "None" condition since we require to choose a deployment platform.

I saw that you've used logger, how do I use it and where I can see logs in JIRA?

Like Fadoua likes this

Hi @Zachi Meyer ,

Good to know it works for you.

I saw that you've used a logger, how do I use it and where I can see logs in JIRA?      

Adaptavist provides some documentation you can refer to on how to set a log and how to view your log.

Glad to know this is what you are looking for.

Regards,

Amir

Like Fadoua likes this
0 votes
Fadoua
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Feb 17, 2021

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

Kristian Walker _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.
Feb 17, 2021 • edited

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Feb 18, 2021

@Zachi Meyer I will try as well later tonight.

Hi @Fadoua  and @Kristian Walker _Adaptavist_ ,

I wrote this code like this guide here,

but it still doesn't work ... what am I missing? :(

import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript

def impactAnalysisField = getFieldByName("Impact Analysis");
def deploymentPlatformField = getFieldById(fieldChanged);
def deploymentPlatformFieldValue = deploymentPlatformField.value;


def chosenValuesList = []
if (deploymentPlatformFieldValue in String) {
chosenValuesList.add(deploymentPlatformFieldValue)
} else if (deploymentPlatformFieldValue in ArrayList) {
chosenValuesList.addAll(deploymentPlatformFieldValue)
}

if (chosenValuesList == ['Mobile']) { // if mobile was chosen as deployment platform field
ImpactAnalysisListField.setRequired(true);

// If the user has selected "None" and another value
} else if ('None' in chosenValuesList) {
ImpactAnalysisListField.setRequired(false);

// If the user didn't select any value, or has selected some values, but NOT the "None" value
} else {
ImpactAnalysisListField.setRequired(false);
}
Kristian Walker _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.
Mar 09, 2021

Hi Zachi,

If you are experiencing issues with the code that you have written where it is not working as expected then I would advise you to create a support ticket located in our support portal here, so that my colleagues in our server support team can help advise on why the script is not working as expected.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events