I have a behavior script that works to make a field required based off of the value in another field. But I need to include and AND condition and a NOT EQUALS condition.
Initialiser = Launch type
IF Launch Type = A
AND Field Value != Z
then require field X
Here is my server side script, but how do I include an AND/NOT EQUALS condition?
if (launchtypeField.getValue() == "Affiliate-New")
AND (NetworksField.getValue() !== "JP")
{
affiliateMIDField.setRequired(true)
affiliateMIDField.setHelpText("Please provide the Affiliate MID for this client")
}
else {
affiliateMIDField.setRequired(false)
affiliateMIDField.clearHelpText()
I cannot find a statement that works.
Please help
@Becky ComptonCould you try and see if the two "if" statements in sequence work for you, like below:
Note: Put the script code for both "Launch Type" and "Networks" fields.
if ((launchtypeField.getValue() == "Affiliate-New")
&& (NetworksField.getValue() != "JP"))
{
affiliateMIDField.setRequired(true)
affiliateMIDField.setHelpText("Please provide the Affiliate MID for this client")
}
if ((launchtypeField.getValue() == "Affiliate-New")
&& (NetworksField.getValue() == "JP"))
{
affiliateMIDField.setRequired(false)
affiliateMIDField.clearHelpText()
}
@Becky Compton Did my suggested code snippet work for you?
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 @Becky Compton
Your script is right, it seems that you place you script into initialiser function
If so, this is the reason it didnt work, because Initialiser function runs only once when form loaded.
try to : Your behaviour -> fields -> Add field (choose launchtypeField) -> add server-side script on it and place code
import com.onresolve.jira.groovy.user.FormField
FormField launchtypeField = getFieldById("customfield_19229")
FormField affiliateMIDField = getFieldById("customfield_19264")
if (launchtypeField.getValue() == "Affiliate-New")
{
affiliateMIDField.setRequired(true)
affiliateMIDField.setHelpText("Please provide the Affiliate MID for this client")
}
else {
affiliateMIDField.setRequired(false)
affiliateMIDField.clearHelpText()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Mark Markov,
I do have the behavior set on the field and it does work correctly as is, but what I am trying to do is enhance it to include either an OR statement or an AND statement.
I was able to resolve the OR statement with pipes (||), but the AND statement is not working. Below is what I have to be able to say "if X = A and Y!=B", but this code is not working. Any chance you can help me correctly write the AND part of the statement below?
Example:
if (launchtypeField.getValue() == "Affiliate-New")
AND (NetworksField.getValue() !== "JP")
{
affiliateMIDField.setRequired(true)
affiliateMIDField.setHelpText("Please provide the Affiliate MID for this client")
}
else {
affiliateMIDField.setRequired(false)
affiliateMIDField.clearHelpText()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have modified my original description to match what I am asking.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this
if ((launchtypeField.getValue() == "Affiliate-New")
&& (NetworksField.getValue() != "JP"))
{
affiliateMIDField.setRequired(true)
affiliateMIDField.setHelpText("Please provide the Affiliate MID for this client")
}
else {
affiliateMIDField.setRequired(false)
affiliateMIDField.clearHelpText()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Mark Markov, But it behaves no different with the
&& (NetworksField.getValue() != "JP")
added in. It still shows the required field and message text if the "JP" value is selected. I appreciate the assistance, any other ideas of how to structure this statement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is your scriptrunner version?
And where you place this code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Version 5.2.2 I am placing the code in the Field behavior operation "validation (server side) script"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
initialiser or attached to some field?
Can you provide screenshot?
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.
Oooh, the problem is clear. When you link script to the field it only runs when linked field updated.
In your case you update LaunchType field and network field become required. And when you update Network field nothing happens because behaviour didnt run.
So you need also add this script to Network field and it will work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mark Markov I have added the Networks field to the behavior (see screenshot), but when I update the Network field to be "JP" it does not clear the message. Am I missing something?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Becky Compton as I see on screenshot you are forgot to copy script to Networks field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mark MarkovAh - thank you! I have added the script to the second field and it still does not change the behavior
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.