Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to make a custom field required when check box is checked?

Irshad Sheik April 11, 2019

I have a check box that if checked it needs to validate that a separate  custom field needs to contain data or the ticket cannot be closed. however if the check box is not checked the the custom field can remain empty.

2 answers

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2019

Hello @Irshad Sheik 

It's not possible out of the box, I have implemented something similar using the Behvaiour module of the Script runner paid plugin.

Possible duplicate 

https://community.atlassian.com/t5/Jira-Core-questions/Script-Runner-Behaviours-Hide-Show-based-on-checkbox-selection/qaq-p/306754

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 12, 2019

Hello @Irshad Sheik 

Have you gone through the link which I have shared above as it contains a pretty similar code snippet which is required in your scenario.

Irshad Sheik April 12, 2019

i have gone thru the link, but im still struggling on this, ive gotten so far:

def checkBoxField = getFieldByID()
def checkBoxFieldVal = checkBoxField.getValue()
def BI = getFieldByName('Billing Instruction')

if (checkBoxFieldVal == 1){

}

not sure if im on the right path or whats left.

0 votes
Alex Shmakov April 11, 2019

Hi Irshad
I'm afraid it is not possible with out-of-the-box Jira validators.
You should use something like Power Scripts For Jira to create a custom validator with if-else conditions.
Here is an example of script that could be helpful
https://confluence.cprime.io/display/TR/Validators#Validators-Forceacustomfieldtoberequiredifanotherfieldwassettoacertainvalue 

Irshad Sheik April 12, 2019

Morning

 

i tried the following and am getting an error:

string errorMsg = "Please enter Billing Instruction Number";
if (customfield_13500 == 1 && !hasInput("customfield_13600")) {
return false,"customfield_13600", errorMsg;
}

the comma after false is producing an error saying expecting } but got ,

Alex Shmakov April 12, 2019

I think there is some error in how you specifying custom fields and its value.
On my test instance it throws a different error and if i change fields to those i got on my instance and hit Check it says "Looks good"

Try to use this 

string errorMsg = "Please enter Billing Instruction Number";
if ("customfield_13500" == 1 && !hasInput("customfield_13600")) {
return false, "customfield_13600", errorMsg;
}

Also you should open any issue that contains those fields with JSON representation and check if field names and value you specifying are correct.

For JSON representation


https://<your jira URL>/rest/api/2/issue/<issuekey>?expand=names

Irshad Sheik April 12, 2019

would it matter that im using script runner and not power scripts??

Alex Shmakov April 12, 2019

Yes. Power Scripts using Simple Issue Language and ScriptRunner is using Groovy. Scripts from Power Scripts not compatible with ScriptRunner. 

With Power Scripts its much more easy to start, but ScriptRunner is more powerful in some cases.

For this case i rather use Power Scripts then Script Runner, but if you more familiar with groovy then Script Runner will probably be better. 

Irshad Sheik April 12, 2019

so we use Script runner, guess i need to start from scratch now, apologies for not highlighting this from the start

Alex Shmakov April 12, 2019

No problem.
If you get stuck with Script Runner, feel free to raise support request on vendor's service desk.

https://productsupport.adaptavist.com/servicedesk/

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events