While using JIRA, you normally want to resolve an issue to the person that created the issue. This way, that reporter can check whether the issue is resolved correctly and close the issue.
While this is described here, I decided to sum up the whole procedure to save other people some time.
Creating a custom field
The first step is to create a custom field. I gave it the name “Set assignee to reporter” and the following description (yes, this javascript):
<script type="text/javascript">
/* CUSTOMIZE THESE VALUES */
var jiraUrl = "<YOUR_JIRA_URL_HERE>";
var customFieldId = "<YOUR_CUSTOM_FIELD_ID>";
/* DO NOT MODIFY SCRIPT BELOW */
function getAssigneeControl() {
var setAssigneeToReporterField = document.getElementById("customfield_" + customFieldId);
var parentContainer = jQuery(setAssigneeToReporterField).parents("#issue-workflow-transition");
return parentContainer.find("#assignee");
}
function getAssignee() {
return getAssigneeControl().val();
}
function setAssignee(newAssignee) {
var assigneeControl = getAssigneeControl();
//console.log("setting assignee from '" + assigneeControl.val() + "' to '" + newAssignee + "'");
assigneeControl.val("" + newAssignee);
//console.log("assignee should now be " + newAssignee);
}
jQuery(document).ready(function() {
var setAssigneeToReporterField = document.getElementById("customfield_" + customFieldId);
setAssigneeToReporterField.parentNode.style.display = 'none';
//console.log("Searching for issue id");
// Parse issue key from title
var issueText = jQuery(".dialog-title").html();
var startIndex = issueText.indexOf('[');
var endIndex = issueText.indexOf(']');
var issueId = issueText.substring(startIndex + 1, endIndex);
//console.log("Found issue " + issueId);
// Get reporter via REST
var restUrl = jiraUrl + "/rest/api/latest/issue/" + issueId;
//console.log("Getting data from url " + restUrl);
// Do a synchronous request (otherwise it will not work, don't blame me!)
if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();
else if (window.ActiveXObject) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", restUrl, false);
xmlhttp.send(null);
var data = jQuery.parseJSON(xmlhttp.responseText);
//console.log("Retrieved data from url " + restUrl);
var currentAssignee = getAssignee();
var reporter = data.fields.reporter.name;
if (currentAssignee == reporter)
{
alert("Important, you are both the reporter and assignee. Make sure to double check the assignee.");
}
setAssignee(reporter);
});
</script>
This way, as soon as the document is loaded, it will search for the fields and set the values correctly. As soon as the values are set, it will hide the custom field.
Add the custom field to the resolve issue screen
It is important to add the custom field to the “Resolve issue screen”:
- Set assignee to reporter custom field
That’s all! Now when you resolve an issue, the assignee is automatically set to the reporter. You can of course also set the main tester in the javascript, it works the same and saves you a lot of manual steps 