Behaviours Scripting - AND/!= statement

Becky Compton July 19, 2018

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

3 answers

1 vote
Taranjeet Singh
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 28, 2018

@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()
}
Taranjeet Singh
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 19, 2018

@Becky Compton Did my suggested code snippet work for you?

0 votes
Becky Compton July 23, 2018

@Jon Bevan [Adaptavist] - is this something you might be able to give direction on?

0 votes
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 19, 2018

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()
Becky Compton July 23, 2018

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()
Becky Compton July 23, 2018

 I have modified my original description to match what I am asking.

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2018

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()
}
Becky Compton July 24, 2018

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?

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2018

What is your scriptrunner version?

And where you place this code?

Becky Compton July 31, 2018

Version 5.2.2  I am placing the code in the Field behavior operation "validation (server side) script"

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2018

initialiser or attached to some field? 

Can you provide screenshot?

Becky Compton August 1, 2018

Attached to the field (I believe):  See attached screenshot

image.png

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 1, 2018

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.

Becky Compton August 2, 2018

@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?image.png

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 2, 2018

@Becky Compton as I see on screenshot you are forgot to copy script to Networks field

Becky Compton August 2, 2018

@Mark MarkovAh - thank you!   I have added the script to the second field and it still does not change the behaviorimage.png 

Suggest an answer

Log in or Sign up to answer