Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set Priority from Behaviour in JIRA 5.1

rahulkhire February 11, 2013

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

2 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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

rahulkhire February 11, 2013

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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 ?

rahulkhire February 11, 2013

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.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2013

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

rahulkhire February 12, 2013

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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 ?

rahulkhire February 12, 2013

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.

rahulkhire February 13, 2013

Mizan, Jamie,

Let me know if you have seen this issue earlier.

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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 .

rahulkhire February 20, 2013

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 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 Sign up to answer