clear or set Assignee to 'null' if (Reporter == Assignee)

this is my first question here, i hope i convey it well for you to understand, i want a button to display on issue details page in Jira. when clicked it would check if (Report == Assignee) and set 'Assignee' to 'NULL' or clear that field.

If you have any other suggestions please let me know how can i implement this better or how can i do it using 'GroovyRunner' plugin...

8 answers

1 accepted

Hi,

I dont have idea about groovy script but you can do this with java script too or writing a post function is also a better way.

If you wanna do using Java script, then here is how to do it,

Create a plugin,

write a javascript code as below,

jQuery(document).ready(function($) {
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
        checkAssignee();
    });
    checkAssignee();
    function checkAssignee(){
         AJS.$('#checkButtonId').click(function() {  
               if($('#reporterId').val() == $('#assigneeId').val()){
                    $('#assigneeId').val() = "";
               }
            });
    }
});

In your atlassian-plugin.xml add the following

<web-resource key="checkassignee-js" name="editissue">
        <description>check assignee and reporter are same
        </description>
        <resource name="checkassignee.js" type="download"
            location="templates/js/checkassignee.js" />
        <context>atl.general</context>
    </web-resource>

Add the .jar to the plugins

Hope this helps.

thanks this looks like a solid solution, can you tell be where is 'atlassian-plugin.xml' located. i can't find it. also what do you mean by 'Add the .jar to the plugins'

thanks again

HI,

If you are comfortable with groovy and you are able to solve your problem, then its fine. If you haven't done that, then you can look upon this,

We will be creating a maven plugin and how to create a maven plugin, you can see jobin kuruvilla's pdf document and once you are done with the plugin, you need to do a maven package, where it will create a .jar file under the target folder. You have to take it and upload it in jira, under manage plugins, you'll be able to see upload plugin.upload the .jar file.Once you do this. It will work.If you have any doubt check the document.

Hope this helps

i'll definitly look into it, can you link the pdf.

thanks i'll let you know about this

thanks but i can't get it to work, i created a webitem. and i want to call this jquery function you wrote.

i have created a plugin but i can't get it to work. can you please help me on this, cause i think doing this would be better as it would do it on the fly. thanks again.

You can try the below groovy script and use it as the post function on Create Issue transition.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.Permissions
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.jira.groovy.autoassign")
def componentManager = ComponentManager.getInstance()
def currentUser = componentManager.jiraAuthenticationContext?.user
def permissionManager = componentManager.getPermissionManager()
if (! issue.assigneeId)
{
if (permissionManager.hasPermission(Permissions.ASSIGNABLE_USER, issue, currentUser))
{
issue.assigneeId = currentUser.name
}
}

it gives me an error

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issue for class

How are you running your script. Try saving the file as setassignee.groovy, and then run it by adding this post function - C:\setassignee.groovy under the Create Issue transition by putting the post function before the - 'Create Issue Originally'

thanks doing this right now, i'll let you know

Glad to know that. If it works fine, then feel free to accept my answer!;)

ok i have added it into the transition but i don't think it is executed, how can i know if is executed or should it give errors or something...

Mizan Community Champion Dec 02, 2012

Check the atlassian-jira.log file located in jira-home directory . Also check if you have provided a correct path and i guess you will need to put the post function after 'Create Issue Originally' .

i edited that script given by Naren to my liking, thanks to everybody here (Naren, Nitram and Mizan)

here is the code and letting me know who to add code in transition helped me also. thanks again

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.Permissions
import org.apache.log4j.Logger
def log = Logger.getLogger("com.onresolve.jira.groovy.autoassign")
def componentManager = ComponentManager.getInstance()
def currentUser = componentManager.jiraAuthenticationContext?.user
def permissionManager = componentManager.getPermissionManager()
if (issue.reporterId == issue.assigneeId)
{
issue.assigneeId = ''
}

Using a post function is the most appropriate solution.

HI Javed,

Use fire bug or you can also use ctrl+shift+i (firefox,chrome..) to identify the id of the web item that you have created.Give it in the following code,

AJS.$('#webitemId').click(function() {

When you click on the web item it will initiate the other process.

Hope this helps.

how can i change the functionality of 'assign to current user' to assign to none.

can you provide sample code and how to run it.

How about adding a post function 'Assign to Current User' on Create Issue step in the workflow?

Go through the below links. This post function will set the assignee to the current logged in user i.e., the reporter. Though this approach doesn't matches your exact requirement, but by applying this post function, the reporter will always be the assignee for the issue, which he is creating.

This approach eliminates the effort to check- if assignee is not the reporter, then make the set the Assignee field to Unassigned.

Hope it helps!

https://confluence.atlassian.com/display/JIRA/Configuring+Workflow

https://confluence.atlassian.com/display/JIRA/Configuring+Workflow

thanks for letting me know, but if you could come up with a groovyrunner script. i have been trying this code but it is giving me error

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
 
//def componentManager = ComponentManager.getInstance()
//def currentUser = componentManager.jiraAuthenticationContext?.user
//def permissionManager = componentManager.getPermissionManager()
def MutableIssue issue = issue
def componentManager = ComponentManager.getInstance()
issue = componentManager.getIssueManager().getIssueObject("JRA-1306")
def userUtil= componentManager.getUserUtil()
def usera = issue.reporterId
def userb = issue.assigneeId
if (usera == userb) {
        issue.setAssignee('');
	}

0 votes
Joe Pitt Community Champion Dec 02, 2012

You realize by clearing the Assignee field the Assigned to Me built in report won't show the work truely assigned to people? What is the value in clearing the field when what you are actually trying to indicate the issue is assigned to the reporter? By comparing the fields you're saying it is already assigned to the reporter. Remember, you'll need to maintain the mod for each future release.

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

2,890 views 12 18
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