I have an existing behaviour that I need to update to include a check for transition to "In Requirements', then set the field to required. Any suggestions would be greatly appreciated.
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
def WorkTypeField = getFieldByName("Work Type")
def projectCat = issueContext.projectObject.projectCategory
def defaultValue = null
log.debug ("project category: " + projectCat)
if (transition to "In Requirements"){
if (projectCat.name.toString() in ["Software Delivery Teams","Business Prioritized"]) {
WorkTypeField.setRequired(true)
WorkTypeField.setHelpText ("Work Type must be filled in once moved to 'In Requirements'")
}
}
else {
WorkTypeField.setRequired(false)
WorkTypeField.setHelpText ("")
WorkTypeField.setFormValue(defaultValue)
}
Hi @SMAtlassianMber ,
I would suggest you test against the transition name, and if not enough the current status :
if (getActionName() == "In Requirements" && underlyingIssue?.getStatus().getName() == "Your status")
Antoine
Hello @Antoine Berry - I tried replacing my note below
if (transition to "In Requirements"){
with your example and the behaviour didn't work. I'm not sure how it will force the user to input the work type at the transition when we have no screen assigned.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, I thought you had a screen assigned.
Then you can simply add a script validator in the transition :
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
int customFieldId = 13302
def customField = customFieldManager.getCustomFieldObject(customFieldId)
def customFieldValue = issue.getCustomFieldValue(customField)
if (customFieldValue == null || customFieldValue == ""){
throw new InvalidInputException(customFieldId,"This field is mandatory.")
}
(replace the id of the custom field with yours)
Not sure what type your custom field is but this should work with most.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry - Created a new screen with just work type and added it to the transition. Now if I could just hide the field. This is close, but it always hides the field, so it's not capturing the 1st part of the if statement.
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
def WorkTypeField = getFieldByName("Work Type")
def projectCat = issueContext.projectObject.projectCategory
def defaultValue = null
log.debug ("project category: " + projectCat)
if (projectCat.name.toString() in ["Software Delivery Teams","Business Prioritized"]
&&
(getAction().id == "13600"))
{
WorkTypeField.setRequired(true)
WorkTypeField.setHidden(false)
WorkTypeField.setHelpText ("Work Type must be filled in once moved to 'In Requirements'")
}
else {
WorkTypeField.setRequired(false)
WorkTypeField.setHelpText ("")
WorkTypeField.setHidden(true)
WorkTypeField.setFormValue(defaultValue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should add :
log.error("project category: " + projectCat)
log.error("action : " + getAction().id)
before the if and check the logs when triggering another transition.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Antoine Berry . I have located the action id and updated the script. Still not working. It still always hides the field. Works fine with just the first part of the if once I add the 2nd condition it stops working. I just noticed it works for the issue types not mapped.
def WorkTypeField = getFieldByName("Work Type")
def projectCat = issueContext.projectObject.projectCategory
def defaultValue = null
log.error ("project category: " + projectCat)
log.error ("action : " + getAction().id)
if (projectCat.name.toString() in ["Software Delivery Teams","Business Prioritized"]
&& (getAction().id == "291"))
{
WorkTypeField.setRequired(true)
WorkTypeField.setHidden(false)
WorkTypeField.setHelpText ("Work Type must be filled in once moved to 'In Requirements'")
}
else {
WorkTypeField.setRequired(false)
WorkTypeField.setHidden(true)
WorkTypeField.setHelpText ("")
WorkTypeField.setFormValue(defaultValue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Antoine Berry - Nothing is being logged when I use a different transition, but the log is prior to the if.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Problem solved. I replaced && with || and now it's working.
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.
@Antoine Berry - Well it's working, but for some reason it is also making work type required at creation, but not at any other transition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is my latest update. || is for OR. No longer having problems with create or issue that do not meet the project category, but now it's hiding the work type field when the criteria is meet and the transition is 291. I believe my new problem is related to the transition && (getAction().id == "291")). I think it needs to be more defined to work, but nothing I try is working.
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
def WorkTypeField = getFieldByName("Work Type")
def projectCat = issueContext.projectObject.projectCategory
def defaultValue = null
log.debug ("WorkType Behaviour")
log.debug ("action : " + getAction().id)
if (projectCat.name.toString() in ["Software Delivery Teams","Business Prioritized","IT Prioritized"]
&& (getAction().id == "291"))
{
WorkTypeField.setRequired(true)
WorkTypeField.setHidden(false)
WorkTypeField.setHelpText ("Work Type must be filled in once moved to 'In Requirements'")
}
else {
WorkTypeField.setRequired(false)
WorkTypeField.setHidden(true)
WorkTypeField.setHelpText ("")
WorkTypeField.setFormValue(defaultValue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It was a syntax error -
Before: if (projectCat.name.toString() in ["Software Delivery Teams","Business Prioritized","IT Prioritized"]
&& (getAction().id == "291"))
{
After: if (getAction().id == 381 && projectCat.name.toString().contains ("Software Delivery Teams","Business Prioritized","IT Prioritized")
{
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well
contains
is more permissive than
in
since the latest checks exactly for the string. Both syntaxes should work but will not have the same result.
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.
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.