Behaviours Plugin:Making a field mandatory depending on other data entered in to the form by script

I have a similar problem,

1.

on “new issue” or “edit issue” screen, if the field “Priority” is set to either Blocker, the field “Due Date” should be mandatory. Respectively, if the field “Priority” is set to Trivial, Minor, etc., the field “Due Date” should be optional.

2 I add a script liske this"

public void setEnvironmentWhenHighPri () {
FormField priField = getFieldByName("Priority")
FormField dueField = getFieldByName("due date")

if (priField.getFormValue() == "1") { // Blocker priority
dueField.setHelpText("<div class=\"warningBox\">Please explain why priority is Blocker.</div>")
dueField.setRequired(true)

}
else {
dueField.setRequired(false)
}
}

anyone can help me, where is the problem in this script.

1 answer

0 vote

I think "due date" should be "duedate". At least log.warn the value of dueField, so you cna see if it's null.

Any errors in the log?

btw, I have enable log by the link on the Behaviours admin screen, thanks.

Thanks for your quickly reply, I have updated " FormField dueField = getFieldByName("duedate"), but still does not work, even I updated the condition to " if ("1" == "1")".

Sorry, I didn't find error message about this in log file atlassian-jira.log, do you have any other suggestion about this, thanks again.

Gary

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

182 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you