Assignee field: Any way to get rid of "automatic" or set currentUser as default?

Hi,

my current customer is by far not happy the way JIRA handles the assignee field. So I'm hoping one of you can help me out...

1. Has anyone achieved to get rid of the "automatic" pre-poplulation of the assignee field? Iwould need it to be either empty or prepopulated with the current user. I've achieved prepopulating a custom user picker with the current user but adapting this script (behaviours plugin) to the assignee field won't work . Using a post-function won't work either since the user should be offered the possibility to select another assignee upon issue creation.

That was my script:

import com.atlassian.jira.ComponentManager

FormField formAG = getFieldByName("Auftraggeber")       

currUser = ComponentManager.getInstance().getJiraAuthenticationContext().getUser()
currUserName = currUser.getName()

if(!formAG.getFormValue()){     
 formAG.setFormValue(currUserName) 
 }

2.Is there anyway to get rid of the assign to me link right next to the field on my screen? I don't see any ponit in removing this feature, but anyway my customer wants this to be evaluated... Deactivation the issue operation "Assign to me" doesn't do the trick.

The first question is by far more important to me... (and my customer). Any ideas are being appreciated.

6 answers

1 accepted

Accepted Answer
1 vote

Cristian, can't get your point. I've checked my code in firebug - works fine.

There is no console.log in my code. Could you explaint, what's the problem?

Hey Grigory,

no problem so far. I'm just trying to use your code using Behaviours Plugin. I'm not a Javascript expert so it takes some time for me to figure out what your code is doing and to edit it in order to just setting the assignee to current user. The "assign to me blocking works just fine":-)

Ah, that's what the problem! My code is supposed to use as is - without Behaviours Plugin. Just paste it in field's description, as described here.

hope, it helped.

I've also tested the other script you mentioned in your post

var value = "test1"; AJS.$("#assignee-field").val(value); AJS.$("#assignee").find(":selected").data("descriptor").model()[0].value = value;

When I change the first line to "value = JIRA.Meta.getLoggedInUser();" I get an output like this: [object Object]

Hi,

I've tried a code you provided in another post:
https://answers.atlassian.com/questions/59501/change-assignee-via-javascript

That's how my description field looks like:

<script type="text/javascript">
var loggedInUser = JIRA.Meta.getLoggedInUser(); var assigneeSelect = $("#assignee", context); assigneeSelect.trigger('set-selection-value', loggedInUser.name); 
</script>

No effect. What am I doing wrong?

Oh, there were some bugs in script. Here is one that works for me:

<script type="text/javascript">
    var loggedInUser = JIRA.Meta.getLoggedInUser(); 
    var assigneeSelect = AJS.$("#assignee"); 
    assigneeSelect.trigger('set-selection-value', loggedInUser.name);
</script>

Hey Grigory, that one works!!! Thank you so much. Just ONE last question :-)

Applying this script to the description field changes the assignee to the LoggedInUser every time I edit the issue, right?
I only wnat this to happen upon issue creation. Is there a way to achieve this like:

... if(assigneeSelect = "Automatic") ....?

Here you go:

<script type="text/javascript">
if (AJS.$("#assignee").val()[0] === "-1"){
    var loggedInUser = JIRA.Meta.getLoggedInUser(); 
    var assigneeSelect = AJS.$("#assignee"); 
    assigneeSelect.trigger('set-selection-value', loggedInUser.name);
}
</script>

Brilliant, thank you so much for your time!

Hello!

We've encountered a similar problem - change assignee, depending on other field. So, here is piece of javascript we use to change assignee:

function changeAssignee(value){
    var assignee = AJS.$("#assignee");
    var model = new AJS.SelectModel({
             element: '#assignee',
             removeOnUnSelect: false
         });

    JIRA.SmartAjax.makeRequest({
        url: "/rest/api/2/user", 
        data: {username: value},
        complete: function (xhr, status, response) {
            if (response.successful){
                var descriptor = new AJS.ItemDescriptor(
                {
                    value: response.data.name, 
                    fieldText: response.data.displayName,
                    label: response.data.displayName, //+ ' - ' + response.data.emailAddress + ' (' + response.data.name + ')',
                    allowDuplicate: false,
                    icon: response.data.avatarUrls['16x16']
                });

                model.setSelected(descriptor);
                assignee.trigger('set-selection-value', value);
            }       
        }
    });
}

You can put this with minor modifications in fields description to make it run each time automatically.

To get current user via javascript you use this:

var loggedInUser = JIRA.Meta.getLoggedInUser();

To get rid of Assign to me use this:

AJS.$("#assign-to-me-trigger").hide()

0 votes
Mizan Community Champion Jul 10, 2012
If you are using Behaviours plugin try the below code
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
 
FormField assignee = getFieldById(fieldChanged)
Object componentFormValue = assignee.getFormValue()
 
 
log.debug("-------------------assignee---"+componentFormValue)
if(componentFormValue=="Automatic"){ 
assignee.setFormValue(ComponentManager.getInstance().getJiraAuthenticationContext().getUser().getName())
}

Mizan Community Champion Jul 10, 2012

There is a system plugin "Issue Operations plugin" in that ther is a module "
View Issue Ops Bar Assign To Me Link" you will have to disable this to get rid of the asssign to me link .

Hey, that's not what I wanted. I just wanted to deactivate it on the screen. Worked with Grigory's promt...

So far I don't get the code you provided working. In the log I just see ("-------------------assignee---"1

Mizan Community Champion Jul 10, 2012

ok , replace the if condition with the below line

if(componentFormValue=="1"){

Hey Mizan,

won't work. I also tried a code you posted in:

https://answers.atlassian.com/questions/59501/change-assignee-via-javascript

import com.onresolve.jira.groovy.user.FieldBehaviours 
import com.onresolve.jira.groovy.user.FormField  

FormField assignee = getFieldById(fieldChanged) 
Object componentFormValue = assignee.getFormValue() 

log.debug("-------------------assignee---"+componentFormValue) 
assignee.setFormValue("test1")

No "if clause" and still no changes...

Mizan Community Champion Jul 10, 2012

do you have test1 as a user ?

Mizan Community Champion Jul 10, 2012

Is that user an assignable user ? do you see the user in the asignee field dropdown ?

I have done this and it should work. check if you are have any typo ;)

Really strange. User is assignable and I copied the script from above so I guess no typos this time:-) The solution Grigory provided does work so I go with that right now even though I'd prefer using behaviours plugin since all my other rules are being set there...

Mizan Community Champion Jul 10, 2012

actually the script triggers when you change the value of some other field and the behaviour should be applied to that field .

I found another solution:

I combined the behaviour-plugin with javascipt and that's the only solution that works for me with JIRA v.5.1.2 to set the assignee depending on antoher field:

Here is the Behaviour-code:

FormField FieldAssignee = getFieldById("assignee") // Feld Bearbeiter
FormField FieldLeistungsklasse = getFieldById ("customfield_10503")

switch (FieldLeistungsklasse.getValue()) {
case null :
FieldLeistungsklasse.setHelpText("<script type=\"text/javascript\">var value=\"cas_admin\";\
AJS.\$(\"#assignee-field\").val(value);\
AJS.\$(\"#assignee\").find(\":selected\").data(\"descriptor\").model()[0].value=value;</script>")
break

case "XS" :
FieldLeistungsklasse.setHelpText("<script type=\"text/javascript\">var value=\"ariu001\";\
AJS.\$(\"#assignee-field\").val(value);\
AJS.\$(\"#assignee\").find(\":selected\").data(\"descriptor\").model()[0].value=value;</script>")
break

case "S" :
FieldLeistungsklasse.setHelpText("<script type=\"text/javascript\">var value=\"hube009\";\
AJS.\$(\"#assignee-field\").val(value);\
AJS.\$(\"#assignee\").find(\":selected\").data(\"descriptor\").model()[0].value=value;</script>")
break

case "M" :
FieldLeistungsklasse.setHelpText("<script type=\"text/javascript\">var value=\"winte02\";\
AJS.\$(\"#assignee-field\").val(value);\
AJS.\$(\"#assignee\").find(\":selected\").data(\"descriptor\").model()[0].value=value;</script>")
break

case "L" :
FieldLeistungsklasse.setHelpText("<script type=\"text/javascript\">var value=\"scill02\";\
AJS.\$(\"#assignee-field\").val(value);\
AJS.\$(\"#assignee\").find(\":selected\").data(\"descriptor\").model()[0].value=value;</script>")
break
}

Hi Christian,

I just came accross exactly the same issues. I want to accomplish these two exact things:

1) getting rid of the automatic value for the assignee field (instead setting it to current user)

2) getting rid of the assign to me link next to the field.

I am new to JIRA and I installed 6.2.2, which it seems it has a lot of incompatibilities (for instance there is not behavious plugin for JIRA 6.2.2 yet).

Can you help me how to accomplish those two things?

Thank you in advance

Grigory, a question related to this: 

I want to clear the Reporter field (so there is no prepopulated default value) on the create issue screen using Javascript in the field configuration (field description). Any idea how I would do that? I can't figure it out. Thanks! 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

23,101 views 2 7
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