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

Christian Czaia _Decadis AG_
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.
July 10, 2012

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

1 vote
Answer accepted
grundic
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.
July 10, 2012

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?

Christian Czaia _Decadis AG_
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.
July 10, 2012

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":-)

grundic
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.
July 10, 2012

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.

Christian Czaia _Decadis AG_
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.
July 10, 2012

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]

Christian Czaia _Decadis AG_
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.
July 10, 2012

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?

grundic
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.
July 10, 2012

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>

Christian Czaia _Decadis AG_
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.
July 10, 2012

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") ....?

grundic
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.
July 10, 2012

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>

Christian Czaia _Decadis AG_
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.
July 10, 2012

Brilliant, thank you so much for your time!

Jose Luis Casarrubias December 9, 2020

Hello,

Can you please explain me More?

Where this code should be set in Jira?

Regards

 

JLuis

1 vote
grundic
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.
July 10, 2012

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()

Ahmed_Bilal July 29, 2020

This is a perfect and proper solution.

0 votes
Sara Wajnberg March 24, 2015

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! 

0 votes
Tomas Arguinzones taart1 June 2, 2014

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

0 votes
Mark Ariu December 2, 2012

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
}

0 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.
July 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
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.
July 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 .

Christian Czaia _Decadis AG_
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.
July 10, 2012

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
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.
July 10, 2012

ok , replace the if condition with the below line

if(componentFormValue=="1"){

Christian Czaia _Decadis AG_
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.
July 10, 2012

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
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.
July 10, 2012

do you have test1 as a user ?

Christian Czaia _Decadis AG_
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.
July 10, 2012

Yes I do . Any ideas?

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.
July 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 ;)

Christian Czaia _Decadis AG_
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.
July 10, 2012

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
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.
July 10, 2012

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

Suggest an answer

Log in or Sign up to answer