Set Priority from Behaviour in JIRA 5.1

I am trying to set the Priority field to a specific value via a Behaviour. This is my code:

import com.atlassian.jira.issue.IssueFieldConstants

import java.util.List

FormField formPriority = getFieldById(IssueFieldConstants.PRIORITY)

List<String> myList = new ArrayList<String>();

myList[0] = "5"

formPriority.setFormValue(myList)

There is no error in the script, but it does not set the value.

Logs show:

/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Returning map: [priority:[setValue:[5], fieldType:com.atlassian.jira.issue.fields.PrioritySystemField, displayName:Priority]]

Anybody knows what is wrong with this script? Does the setFormValue for Priority field take string/list/object?

-Rahul

1 answer

1 vote
Mizan Community Champion Feb 11, 2013

I guess you will need to pass the value of the priority as argument

If we observe the HTML

&lt;option class="imagebacked" data-icon="/images/icons/priority_minor.gif" value="4"&gt; Minor &lt;/option&gt;

value is 4 so ,


formPriority.setFormValue("4")

Will set the priority as minor

Hope this helps

Mizan Community Champion Feb 11, 2013

Add logging to your code . I also see that you are passing the whole list which is not correct , try passing myList[0] as an argument

Thanks Mizan. formPriority.setFormValue("4") worked.

The stange thing is when the behaviour executes on my create issue page, shouldnt the priority field value change there? I can see the behaviour script has executed, but the create page shows the default value only. When I submit the page, I can see the issue is created with my updated priority value.

Mizan Community Champion Feb 11, 2013

Try getFieldById("priority") .

The field should change to the value your are setting to on the create screen as well , have you put any conditions ? what else your script does ?

Yes I tried with getFieldById("priority") as well. After submitting the page the priority changes to the one I want. But the the Priority value in the drop down does not change when I am on the Create page.

I tried putting in a sample Description value, and that comes up properly.

On what field have you added that server-side script?

I have added it on the Summary field change.

Since Summary is the first field on my Create page, change in the Summary field will trigger an update on the Priority field.

Mizan Community Champion Feb 12, 2013

You will need to add the groovy script as a server side script in the priority field . So as soon as the page is loaded the priority will be set according to your script . It will get triggered automatically .

Just to confirm you are adding this script in the text area provided by the behaviours plugin , right ?

Mizan,

Yes, I tried adding for the Priority field as well. The behaviour executes, but the Create page still shows the system default priority.

import com.atlassian.jira.issue.IssueFieldConstants
import java.util.List

FormField formPriority = getFieldById("priority") 
List&lt;String&gt; myList = new ArrayList&lt;String&gt;()
myList[0] = "5"
formPriority.setFormValue(myList[0])

Only after submitting it, can I see the priority set properly on the View page.

The reason I added the behavior on the Summary field was, the user should be able to change the priority if he wants. If I add the behaviuor on the Priority field itself, it will not allow changes to it.

And Yes, the script is in the text area of the Behaviour plugin.

Mizan, Jamie,

Let me know if you have seen this issue earlier.

Mizan Community Champion Feb 13, 2013

I have not seen such issue earlier .

If I add the behaviuor on the Priority field itself, it will not allow changes to it.

This is not correct the user can change the priority later . Your script will execute only once the page is loaded .

I tried the script at my end and observed that the option is disappearing when the script run .

Mizan,

"the option is disappearing when the script run"

I did not understand this. Can you provide the script you used?

I am using JIRA 5.1.8.

Mizan Community Champion Feb 20, 2013

I used the same script same JIRA version , This is probably a bug with Behaviours plugin . You can raise it here

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,188 views 13 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot