make field mandatory for a particular issueType

Ratna Kumar Lekkala July 4, 2017

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

1 accepted

0 votes
Answer accepted
Joe Pitt
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 5, 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.

Ratna Kumar Lekkala July 5, 2017

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 5, 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. 

Like Ratna Kumar Lekkala likes this
0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 4, 2017

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

Suggest an answer

Log in or Sign up to answer