make field mandatory for a particular issueType

I expected this code to make the field mandatory for "Issue Type" = QA or when "Task Type" field is "analysis" or Code Review" for rest of issue types.

 

Its is working for the change in "Task Type" field values, but not working for "Issue Type" = "QA"

What am I doing wrong?

 

 

def selectCFValue = getFieldByName("Task Type").getValue()
def targetField = getFieldByName("SVN Path")
def issueType = getFieldByName("issuetype-field").getValue()
if (issueType == "QA")
targetField.setRequired(true)
else
if (selectCFValue == "Analysis" || selectCFValue == "Code Review")
    targetField.setRequired(true)
else
    targetField.setRequired(false)

2 answers

0 vote

Issue type is not a field (so line 3 is wrong) and when you fetch the object, a simple comparison to a string is never going to work.

Try

if ( "QA".equals (issue.getIssueTypeObject.getName()) )

instead

0 vote
Joe Pitt Community Champion Jul 05, 2017

Why not use a field configuration for that issue type and make it mandatory there? that is built in and no code is required.

Ok, so you are suggseting making a duplicate field configuration for QA task as its now using a shared configuration with other issue tupes that do not need this field as required?

I guess I can do that

Joe Pitt Community Champion Jul 05, 2017

Yes. That is the beauty of the field configuration scheme. You can create different field configurations for each issue type if desired and create the field configuration scheme from them. It is th configuration scheme, not an individual configuration that is tied to the project. 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

767 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you