It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Setting Jira custom field to be required for only one Issue Type Edited

Hello Community People,

I have a project created in our JIRA environment which has around 15 Issue Types. I have two custom fields which I want to make mandatory & visible only on one of the Issue Type. Can someone help with it ?

I have tried it with Behaviour Settings but it's not working.

2 answers

1 accepted

0 votes
Answer accepted

Hi @vishal 

You can set a field required by adding a field configuration  and a field configuration scheme. It's the same as with mapping workflows to issue types. You create the field configuration where you mark your specific fields as required, and in the field configuration scheme, you map it to an issue type.

Afterwards, associate the scheme to the project. More info here: https://confluence.atlassian.com/adminjiraserver/specifying-field-behavior-938847255.html

 

Kind regards
Jorden

Hello Jorden,

Sorry I missed this in question itself, actually I have done the same in in field configuration but it's making it require for all the issue type, which I don't want.

I want it to be require for only one issue type & rest all to be hidden & not required.

Hi @vishal 

Have you perhaps made it required in the default field configuration? This will apply to everything that doesn't have a specific association.

Make sure you have a brand new field configuration and field configuration scheme when making a field mandatory.

Hi @Jorden Van Bogaert 

Yes, I had made default field configuration as required as I didn't want to create more field configuration screen.

I am looking for something like all the issue type should use same screen scheme but using behaviour or something make only those two fields to be available for the one issue type only & remain hidden & not required for rest all.

I am trying to run below server side script using behavior for all the issue type in that project except the one where I want it to be present but it's not working.

def customfield= getFieldById ("customfield_xxxxx")
customfield.setHidden(true);

customfield.setRequired(false);

Hi @vishal 

I still strongly recommend creating an extra field configuration and mapping the specific issue types to the field configuration to make them required so that you're not depending on the user's javascript to be enabled on the browser (as is necessary for Behaviors to work).

However, here's some information that may help you with Behaviours. Jira required fields do not interfere with Behaviours. If Jira says it's required, you can't make it optional with '.setRequired(false)'. You can however keep the field optional and map the Behaviour to the issue types where you do want the requirement and do 'setRequired(true)'.

On the other issue types, you'd map it to a script that says 'setHidden(true)'.

I'd use the initialiser scripts rather than a server side script as you only need it to run once and doesn't need continuous updated (unless you want to change the behaviour depending on the user input).

Hope this helps

Kind regards
Jorden

@Jorden Van Bogaert  could you please check what's wrong with this ?

I am running it on all issue types of that project & expecting the desired output but its not working fully, it does make the field required on issue type "ABC XYZ" but not hiding them from remaining issue types, though they are not required.

I am running this in behaviour :

def custfield = getFieldById ("customfield_xxxxx")
custfield.setHidden(true);


String issueType = IssueContext.getIssueType()
if (issueType == "ABC XYZ" ) {
custfield .setHidden(false);
custfield .setRequired(true);
}

I'll check now and let you know asap.

Hi @vishal 

The following code works for me:

def custfield = getFieldById("customfield_11823")
custfield.setHidden(true);


String issueType = getIssueContext().getIssueType().getName()
if (issueType == "Task") {
custfield.setHidden(false);
custfield.setRequired(true);
}

 Let me know if it works for you to.

Kind regards
Jorden

@Jorden Van Bogaert  unfortunately, no, its not working fully as its unable to hide the custom field from other issue types, rest all is working as expected though.  

Hi @vishal 

Did you put the code as an initialiser? For me it seems to work fine, but I've added it as an initialiser.

Hello @Jorden Van Bogaert I was adding fields & running the script for individual field earlier but even after running it as initialiser, it's not working for me.

Mm, now I'm a bit clueless :/ it works fine here, so I'm not sure what may differ... What Jira & Scriptrunner version are you using?

@Jorden Van Bogaert  honestly, there is no reason for it to not to work but somehow its not :)

We are using scriptrunner v. 5.6.9.

Though for now I have come up with the workaround, a dumb one but it's the only way as intelligent ways are not working :P

I have created two behaviour one with all issue types ( except one which needs them ) where it's hiding the custom fields & second with the issue type where I want the fields to be required. Its working but I'll have to check why the simple code is not working.

Thanks for the help though.

Like Jorden Van Bogaert likes this
0 votes

Hi @vishal ,

You should set an exclusive field scheme for this special IssueType. Associating an issue type with a different field configuration.

https://confluence.atlassian.com/adminjiraserver084/associating-field-behavior-with-issue-types-979404755.html

@Ollie Guan_携程 thanks for the suggestion, I am actually looking for something where in all my Issue Types to use default screen scheme only ( I don't want to create separate for the said issue type ), I am trying to use behavior & is trying to make the fields visible & required for only one issue type.

Do you have any suggestion ? You may see my conversation with Jorden to know what exactly I am doing.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you