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

1 vote
Accepted answer

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

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
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,126 views 0 8
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