Behaviours Plugin- Groovy script does nothing sometimes without an error message

Hi, I've upgraded my Jira as well as its plugins and I have problems with the following Behaviours plugin script:

FormField formOption = getFieldByName("select example")
FormField formUserField = getFieldByName("Preview")
FormField formMailOption = getFieldByName("Email template")
tamplate = formMailOption.getFormValue()
tamplate = tamplate.replaceAll(' ','_')
def input = new File('mail/template/'+tamplate)
formUserField.setFormValue(input.text)
if (formMailOption.getFormValue() == 'Send solution') {
	formOption.setHidden(false)
	formUserField.setFormValue(input.text.replaceAll('\\$\\$SOLUTIONS',''))
} else {
	formOption.setHidden(true)
}

The behaviour work sometimes and on other times does nothing. I've opend the same issue in two browser windows and changed this behaviour field, on one window it workd and in the other it didn't. after refreshing the page sometimes it worked, and again, some time it didn't... there are no error messages in either of Jira's logs.

What am I doing wrong? how can I debug this? Thanks.

2 answers

1 accepted

Since I had no way to debug this, I gave up on the behaviour plugin and wrote it using jquery:

AJS.$("#customfield_10402").bind("change", function () {
		var selected = AJS.$(this).val();
		// show solution panel if needed
		var solutionPanel = AJS.$("#customfield_10404").parent();
		if (selected == 'Send solution') {
			solutionPanel.slideDown();
		} else {
			if (solutionPanel.is(":visible")) {
				solutionPanel.slideUp();
			}
		}
 		// load template
		var file_name = selected.split(' ').join('_');
		AJS.$.ajax({
			url: "/mail/template/"+file_name,
			type: "GET",
			data: ({projectsOnly : "true"}),
			dataType: "html",
			success: function(template){
				AJS.$("#customfield_10403").text(template);
				if (selected == 'Send solution') {
					sendSolutionTemplate = template;
				}
			}
		});
	});

0 vote

Sorry, been on holiday.

formMailOption.getFormValue()

won't work post-jira 4.3, it will give you the ID of the Option object. It should be Field.getValue().

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

181 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