Hello,
Is there a way to make custom field called " ECC Reason" required if the Label is selected as " Emergency" ?
If this can only be done by a script runner , do you have any samples?
Thank you.
We use JIRA 7.5.0
Elif
Hello @Elif Alverson
If your quiestion actual.
Yes, as David say, you need behaviour mapped to the labels field.
But labels field is special one. When there is only one label it is String object, but if there two or more its List<String> object, so keep it in mind, we can make script like this:
def labels = getFieldById(getFieldChanged())
def targetField = getFieldByName("ECC Justification")
targetField.setRequired(false)
if ("EmergencyChange".equals(labels.getValue()) || labels.getValue().find {it == "EmergencyChange"} ){
targetField.setRequired(true)
}
I check it on ScriptRunner v5.4.7, it works! Hope it help you!
Thank you for your response. It works on transition step " Submit for Approval".
We need " ECC Justification" to be required only for transition " Resolved".
I put the conditions however it does not work.
Any ideas?
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Elif Alverson
You can use method getActionName() to find current transition, see code bellow
if ("Resolved".equals(getActionName())) {
def labels = getFieldById(getFieldChanged())
def targetField = getFieldByName("ECC Justification")
targetField.setRequired(false)
if ("EmergencyChange".equals(labels.getValue()) || labels.getValue().find { it == "EmergencyChange" }) {
targetField.setRequired(true)
}
}
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 tried however it does not work. I can resolve issues with EmergencyChange labels without filling " ECC Justification" custom field.
Any idea why?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getActionName() contains transition name, in your case it seems transition have name "Resolve Issue", so this name must be in code:
if ("Resolve Issue".equals(getActionName())) {
def labels = getFieldById(getFieldChanged())
def targetField = getFieldByName("ECC Justification")
targetField.setRequired(false)
if ("EmergencyChange".equals(labels.getValue()) || labels.getValue().find { it == "EmergencyChange" }) {
targetField.setRequired(true)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tried it, still no change. " ECC Justification" is not required.
See below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Remove conditions above. Leave only the script.
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.
I check it on my local environment and it work perfectly, are you sure that transition name is correct in script? Try to add log.error() after condition and see logs, to make sure that behaviour runs correctly on screen we need
if ("Resolve Issue".equals(getActionName())) {
log.error("Behaviour start on screen Resolve issue")
def labels = getFieldById(getFieldChanged())
def targetField = getFieldByName("ECC Justification")
targetField.setRequired(false)
if ("EmergencyChange".equals(labels.getValue()) || labels.getValue().find { it == "EmergencyChange" }) {
targetField.setRequired(true)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here are the workflow steps below. So when you send the ticket to " resolve issue" , the edit screens pops up saying the " ECC Justification" needs to be filled? How does it work?
We use v7.5.0, does it make any difference?
I do not have access to the logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have some others behaviours?
If there are two or more behaviours executing on the screen and one of them fails, all behaviours fails.
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.
Scriptrunner behaviours:
def dropDown = getFieldByName("Liste1")
def hiddenField = getFieldByName("Liste2")
log.debug("dropdown value" + dropDown.getValue())
hiddenField.setRequired(false)
if (dropDown.getValue() == "aa") {
hiddenField.setRequired(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is what I am trying to do. If Jira user states " Labels= EmergencyChange", then the custom field " ECC Justification" is required.
I tried the script you have provided but nothing happens. What am I doing wrong? Thanks!
Here it is;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are running a script on ECC Justification.
Or you want to have a special behaviours on the change on the fields "Labels".
So you have to move your script from ECC Justification (Fields) to Labels (Fields) on your script attached.
Do you get the point?
You script should be launch on Labels's event
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.
Try to log information:
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.behaviours")
log.setLevel(Level.DEBUG)
log.debug("text to display on log")
Make sure you can get our field. Maybe your can try getFieldById instead of getFieldByName
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you set the correct mapping of this behaviours? Projet / Issue Type?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
where to put this one to see the output;
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.behaviours")
log.setLevel(Level.DEBUG)
log.debug("text to display on log")
Yes, I did set it to correct Project/Issue Type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
something like that directly on your script and log will appear on jira server log
------------------------------------------------
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.behaviours")
log.setLevel(Level.DEBUG)
log.debug("start script")
def dropDown = getFieldByName("Labels")
def requiredField = getFieldByName("ECC Justification")
log.debug("dropdown value" + dropDown.getValue())
log.debug("set required false")
requiredField.setRequired(false)
if (dropDown.getValue() == "EmergencyChange") {
log.debug("set required true")
requiredField.setRequired(true)
}
log.debug("stop script")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@David STOCKY, I will not able to share the logs with you.
Thanks for your time. I need to find another way to make this work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Elif,
There are a few examples in the Community, here is one:
https://community.atlassian.com/t5/Jira-questions/Required-field-and-condition/qaq-p/752807
Hope this helps,
-Scott
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.