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

moxin
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.
December 2, 2012

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

3 votes
Answer accepted
Nitram
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.
December 2, 2012

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.

moxin
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.
December 2, 2012

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

Nitram
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.
December 2, 2012

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

moxin
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.
December 2, 2012

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

Nitram
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.
December 2, 2012
moxin
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.
December 2, 2012

thanks i'll let you know about this

moxin
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.
December 5, 2012

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.

2 votes
Nitram
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.
December 5, 2012

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.

2 votes
Naren
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.
December 2, 2012

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

moxin
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.
December 2, 2012

it gives me an error

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

Naren
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.
December 2, 2012

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'

moxin
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.
December 2, 2012

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

Naren
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.
December 2, 2012

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

moxin
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.
December 2, 2012

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
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.
December 2, 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' .

moxin
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.
December 2, 2012

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 = ''
}

Sameera Shaakunthala [inactive]
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.
December 3, 2012

Using a post function is the most appropriate solution.

0 votes
Joe Pitt
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 2, 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.

0 votes
moxin
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.
December 2, 2012

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
Naren
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.
December 2, 2012

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

0 votes
Naren
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.
December 2, 2012

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

0 votes
moxin
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.
December 2, 2012

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.

Suggest an answer

Log in or Sign up to answer