Making a field non-mandatory using ScriptRunner scripts

Tayyab Bashir
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.
March 9, 2017

Hi,

I have a field mandatory in couple of projects sharing a single workflow. 
I am making this field mandatory using workflow validators on create issue screen for all these projects.

Now there is a project (ABC), and I don't want the field to be mandatory in it. 
Could someone tell me how to do that? 
How can I make an exception for that project without disturbing all the other projects?

P.S. Creating a new field configuration is not ideal for me. And would be the last approach.

Many thanks,
Tayyab 

3 answers

1 accepted

2 votes
Answer accepted
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.
March 9, 2017

Field configurations make  field mandatory from creation time, so I assume you're using validators because you need them optional for part of the lifecycle.  (If you need them mandatory throughout, then you absolutely should be using field configurations)

So, the simple approach - copy the workflow in use, put it in a new workflow scheme for the new project, and strip the validators out of it.

Tayyab Bashir
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.
March 9, 2017

I would need to create both a new workflow and a new workflow scheme for it?

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.
March 9, 2017

Yes, that's one of the things workflow schemes are for - to allow issues to follow different processes.

Slava Gefen March 17, 2022

Hi @Nic Brough -Adaptavist- !
In our server Jira we have a mandatory field and it has to be mandatory indeed. We did it with field configuration. But there is only one case we need this field not mandatory - when there is a specific label. e.g. "NotRequired". Is there a way to avoid this mandatory rule during creation an issue using Scriprunner only in this specific case?
Something like this:

 

def label = labelsField.getValue() as String
def isLabel = label == "NotRequired"
customfield_12345.setRequired(! isLabel)


Can I use it as a post-function during creation?

With kind regards
Slava

 

 

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.
March 17, 2022

No, you can't override that mandatory flag.

If you blank out the field with Scriptrunner, people won't be able to do anything with the issue (other than rank it and report on it) until someone has gone back into it and edited it to fill in the field.

Slava Gefen March 17, 2022

Hi @Nic Brough -Adaptavist- thanks for the answer!

If you blank out the field with Scriptrunner, people won't be able to do anything with the issue (other than rank it and report on it) until someone has gone back into it and edited it to fill in the field.

Nic, it's what exactly we need!

How could we implement this feature on creation?
Can we do this without Behavior?

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.
March 17, 2022

I'm pretty sure you can write a post-function that clears out a field on the create transition (you can definitely do it on other transitions), as it executes after all the validation things.

Slava Gefen March 17, 2022

@Nic Brough -Adaptavist- I forgot to say one important thing: issue is created from an external system (salesforce) and this type of field can't be populated (this is the reason we want to avoid system mandatory rule). We put specific label "salesforce" to know it is from there.

Any chance to avoid it?

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.
March 17, 2022

No.  You need to fill in mandatory fields when you create the issue.

You can blank them out later with code, but the whole point of mandatory fields is that they are mandatory.

Slava Gefen March 21, 2022

You can blank them out later with code, but the whole point of mandatory fields is that they are mandatory.

Many thanks @Nic Brough -Adaptavist- , we will try to find something else, or better to improve the behavior of Salesforce. Have a nice day and week!

1 vote
Vasiliy Zverev
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.
March 9, 2017

I would reccomend to use field configuration scheme beacause it garantee that after creation value for these fields will not be set to null. And these make it simpler to use the same workflow into different projects.

Tayyab Bashir
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.
March 9, 2017

I created a new field configuration, but since the fields are being made mandatory using a workflow validator, I can't make them optional with the new field config, right? 

Vasiliy Zverev
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.
March 9, 2017

You are rigth. That is field configuration for. You have the same workflow, but different mandatory fields into different projects. 

In your case I would reccomend you to define where to reasilse logic for mandatory fields: into field config or into workflow validator.

Benefits for field config:

  • mandatory fields will not be made empty 
  • will be marked with red star on create screen
  • more flexible to use into different projects

 

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.
March 9, 2017

Plus, with field configs, you can carry on using the same workflows.

 

0 votes
Sachin Dhamale March 9, 2017

If you want to use script runner plugin then You can use a behaviour section to make a field mandatory for a specific project and issue type

Suggest an answer

Log in or Sign up to answer