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

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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.

3 answers

1 accepted

1 vote
Answer accepted
Jorden Van Bogaert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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.

Jorden Van Bogaert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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.

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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);

Jorden Van Bogaert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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

Like Millicent likes this
Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

@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);
}

Jorden Van Bogaert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

I'll check now and let you know asap.

Jorden Van Bogaert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

@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.  

Jorden Van Bogaert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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.

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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.

Jorden Van Bogaert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

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?

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

@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
2 votes
Cat Camacho September 30, 2022

I solved this exact issue- 

  • Go to the "custom fields" screen via Admin settings (under Issues)
  • Where you can select "Applicable Issue Types", change the selection from "All issue types" to the issue type where the field you are trying to mark required is located. Please note, this solution only works for fields that exist in one issue type only (that I found.) 
  • Then go ahead and mark required as needed.

This should resolve the "requirement" type on other issue types. If the field you want to mark required is in more than one issue type but you only want it required for one issue type, I would suggest creating a duplicate custom field and assign it to the associated issue types and leave that one unmarked as required. Probably not best practice in reporting, etc. since the fields will be the same and unable to be differentiated but it will work.

Hope that helps.

 

jira settings.png

0 votes
Ollie Guan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 16, 2019

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

Vishal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2019

@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