Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Change assignee to specific user via javascript

Wolfgang Fellner October 28, 2013

https://answers.atlassian.com/questions/59501/change-assignee-via-javascript already gives a good solution to set the assignee in a transition via javascript to the current user.

But i need to change the selected assignee to a specific user.

I tried the following code - but somehow it only works when the specific user (setUser) is equal to the current user:

<script type="text/javascript">
(function($) {
    function setAssignee(){
        var setUser = "someusername";
        var assigneeSelect = AJS.$("#assignee"); 
        assigneeSelect.trigger('set-selection-value', setUser);
    }
    AJS.toInit(function(){  
        setAssignee();
    })
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        setAssignee();
    });
})(AJS.$);
</script>

Any idea what i'm doing wrong?

JIRA 5.2

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
RambanamP
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.
October 28, 2013

did you tried like this ?

AJS.$("#assignee").val(setUser);

the following script is working for me(Just now tested)

<script type="text/javascript">
jQuery(document).ready(function($) {
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        setAssignee();
    });
	 setAssignee();

    function setAssignee(){
        var setUser = "prasad";
        
		AJS.$("#assignee").val(setUser);
    }
       
});
</script>

make sure that user is valid in jira and user should have assignable permission

if you are trying do this function on create screen then load this script as webresource module in a plugin, check this

https://answers.atlassian.com/questions/47843/strange-javascript-problem-in-create-screen

Wolfgang Fellner November 4, 2013

does not work

RambanamP
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.
November 4, 2013

i have updated my answer!!

Wolfgang Fellner November 4, 2013

It works.

Thank you!

0 votes
Bharadwaj Jannu
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.
October 29, 2013

or else you have a default jira workflow postfunction Update Issue Field.

go to workflow and go to transition and add Update Issue Field postfunction, select Assignee and Value to specific user you want.

hope this helps or revert back if any doubts.

Wolfgang Fellner November 4, 2013

I know the assignment via postfuctions. We currently use them. But we want to give users more flexibility - therefore we want to prepopulate the field with the user that is normaly the correct user, but give the users the flexibility to choose an other.

TAGS
AUG Leaders

Atlassian Community Events