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
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since you mentioned behaviour, I assume you have the adaptavist ScriptRunner. If yes I can send you the script.
Please confirm
Best,
Fadoua
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.
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
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.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
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.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Fadoua I switched off the validator but it still didn't work.
Both fields appears on the same screen (Please see the screenshot):
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Zachi Meyer Let's see if Kristian can help as he/she works for Adaptavist
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Kristian Walker _Adaptavist_ thank you very much for your quick assistance! I totally missed the tabs.
@Zachi Meyer Any luck?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Zachi Meyer I will try as well later tonight.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.