Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Separate button for internal comment in JIRA

Svante Gustafsson Björkegren
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.
October 9, 2013

I am setting up JIRA Servicedesk and I think it is awesome!

One thing though that is missing is the possibility to create "internal" comments (i.e. viewable only to the helpdesk agents) easy.

The way it is technically solved is Comment Security levels. But it is too easy though to miss change the security level from "All Users" to "Restricted to members" when creating a comment that shall not be visible to the customer so I think of having a separate button for this.

My approach is to let the standard Comment button be the "All Users" comment and add a transition button for the internal comment. The transition goes to the same status and has an empty transition screen associated to it. This screen will show the comment field only.

When selecting this transition I now want JIRA to automatically set the Comment Security level to Member.

I have put together a javascript which I have injected in the Comment description field in my field configuraton and it works almost as expected. But ...

It seems that JIRA "remembers" the last comment security level in some cases and uses that instead of the one defined in the script.

E.g. If I create a restricted comment it works fine and then if I create an open that works fine too, but not the other way around. When I have created an open comment, the restricted comment created right after will also be for "All Users". In this case I will have to refresh the page and then it works fine again. Weird!

My javascript is based on the examples found here at answers defining a new default security level and I have tweaked it for this use-case. My javascript and jquery knowledge is not sufficient and I hope someone has some ideas how this can be solved.

Rgrds,

// Svante

7 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Svante Gustafsson Björkegren
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.
October 23, 2013

We have managed to remove the Comment box on the transition screens!!!

The following piece of code is injected in a field appearing on the screen in concern:

<script type="text/javascript">
if($('#issue-workflow-transition-submit').val() =='Internal Comment'){
$('div.comment-input').css('display', 'none');
}
</script>

NOTE: This will remove the comment box on the transition screens the field appears on and defined by the if-clause.

Thanks Sana Safai for your assistance in this!

IT Support October 23, 2013

Is this working in Jira 6? I can't seem to get it working (just yet at least anyway). Possibly due to the Ajax popup of the transfer screen

Svante Gustafsson Björkegren
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.
October 23, 2013

There is still a small glitch in this solution.

To reproduce:

  1. Click the standard Comment button to open up the built-in comment editor
  2. While the editor is open, click your transition to add an Internal Comment
  3. Add an Internal Comment and click the "Add" button in the transition screen or back out with the cancel button.
  4. Now the built-in comment editor is hidden and you just see its buttons :-(
  5. Refresh the page and it works again

Any ideas, anyone? It seems that they share the same class which is hidden by the transition screen.

I will look further into this but all ideas are welcome!

Monika Danielsson February 14, 2017

I know this is old and no longer relevant for the poster. But for anyone else who - as I did - stumble upon this years later: you need to hide only the form#issue-workflow-transition instance of the comment field. 

Also, it might be relevant to hide the "internal  comment" field in the bulk edit form in the same way, because if you add a comment there, it will not be purged and it is not protected, and people might be misled by the name. (You can do bulk Internal Comment, but you should do it as a transition instead, that is, emulate clicking the "Internal comment" button.) 

2 votes
Svante Gustafsson Björkegren
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.
October 22, 2013

Hi,

I followed Sergio's advice to put this is a post-function instead and it works fine! Thnx!

This requires the Script Runner plugin!

This is what I did:

1. Created a custom field called Internal Comment (Free text)

2. Created the script below and stored it accesible on my JIRA server

3. Added a transition screen to my transition showing only the newly created custom field

4. Added a post-function to the transition executing the script I added to the server

5. Added another post-function that purged the value in the Internal Comment field (which would show again the next time an Internal Comment is made for the issue :-)

Note: You need to update the roleLevelId (10010 in my script) with the correct role in your instance.

The only thing left to solve now is how to remove the darn Comment-box that appears on every transition screen by default! All ideas are welcome!!! This is so annoying and I haven't found any solution for it yet!

The script below has borrowed sections from Jamie Echlin's scripts on the Script Runner wiki. Thanks!

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
// import org.apache.log4j.Category

// gets a reference to the IssueManager and CustomFieldManager manager classes
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()

// Get the logged in user
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

// gets a reference to the desired issue and custom field
customField_internal_comment = customFieldManager.getCustomFieldObjectByName( "Internal Comment" );

// retrieves the custom field value object from the issue
def internal_comment = issue.getCustomFieldValue( customField_internal_comment );

commmgr = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class)
commmgr.create(issue, currentUser, internal_comment, null,10010, true)
issue.store()

Monika Danielsson February 15, 2017

I know this is old and no longer relevant for the poster. But for anyone else who - as I did - stumble upon this years later: it's worth noting that you shouldn't need to save the issue (issue.store()); the script isn't changing it anyway.

And if you still want to save (maybe because you do something else in your script), and try to use IssueManager.updateIssue (because issue.store() is deprecated), make sure you don't let updateIssue send a mail; the relevant mail will already have been sent by the comment manager.

Also, if you use this script in a post function, make sure you don't fire an event that also sends a mail, after the script. 

1 vote
Sergio October 21, 2013

You could alternatively use a script executed as a post-function that inserts a comment viewable by Members only. It is probably easier.

IT Support October 21, 2013

Even if it's a custom comment and not a scripted/canned comment?

Sergio October 22, 2013

What do you mean by "scripted comment"? This is the solution:

  • A new global transition putting the ticket in the same status (inner transition).
  • The transition screen showing a custom field "New internal comment".
  • A post-function in this transition executing a script which creates a new comment with:
    • the content of "New internal comment"
    • the parameters to make it visible to internal members only

I haven't implemented it, but it seems quite straight-forward to me. Have a thought about it and tell me what you think.

Cheers!

IT Support October 22, 2013

Hi Sergio,

Good idea, I see what you mean now!

However, what would be the parameters to make that comment visible to internal members only (So comment level security, not issue level)?

0 votes
IT Support October 24, 2013

I've come up with a potential solution, slightly different implementation though.

Create a custom field called "Internal Comment security" (doesn't actually matter what you call it), with the following javascript:

<script language="JavaScript">
<!--
var defaultRoleName = "role:10002";
var customRoleSelected = false;function changeCommentLevel()
{
if (customRoleSelected) return;var commentLevelSelect = jQuery('.security-level select#commentLevel option[value=\'' + defaultRoleName + '\']');
if (commentLevelSelect)
{ var labelText = commentLevelSelect.first().text(); jQuery("select#commentLevel").val(defaultRoleName); jQuery("#commentLevel-multi-select a.drop span.icon").removeClass("icon-unlocked").addClass("icon-locked"); var htmlEscapedLabel = AJS.$("<div/>").text(labelText).html(); jQuery(".security-level span.current-level").html(AJS.format(AJS.params.securityLevelViewableRestrictedTo, htmlEscapedLabel)); }}jQuery('#comment').live('focus', changeCommentLevel);
jQuery('#commentLevel-suggestions').live('click', function()
{ customRoleSelected = true; });
//-->
</script><style>
.alertHeader
{display:none;}</style>

Make a transition step and attach the field to a transition screen (you can use tabs to hide the additional fields if you wish).

When you click on the "internal comment" button, the "restrict to administrators" will be automatically set for you.

However, the caveat is as follows: When you make your next (standard) comment, the "restrict to administrators" will be remembered from your script and already be set - you'll need to set the comment security to "all users" manually. However, this is a better solution (better be secure, than to forget to set), than the comment box disapearing.

Works with Jira 6.0.8

0 votes
IT Support October 23, 2013

Try this in the field description:

<script type="text/javascript">
function hideCommentField() {
        var elements = document.getElementsByClassName('field-group aui-field-wikiedit');
        elements[0].style.display = 'none';
}
// http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load
if(window.attachEvent) {
    window.attachEvent('onload', hideCommentField);
} else {
    if(window.onload) {
        var curronload = window.onload;
        var newonload = function() {
            curronload();
            hideCommentField();
        };
        window.onload = newonload;
    } else {
        window.onload = hideCommentField;
    }
}
</script>

It's ugly, but it should work

 


Svante Gustafsson Björkegren
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.
October 23, 2013

I have tried that one with no success! But I found a really simple way to suppress the comment box.

Check out my last answer!

0 votes
Svante Gustafsson Björkegren
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.
October 9, 2013

NOTE: This solution was abandoned! Look at the other solution in this post!

But, of course! Sorry for missing that small detail :-)

The action_id_161 is the workflow action I have created for the restricted comment

<script language="JavaScript">

AJS.$(document).ready(function ($) {


var intervalID;
intervalID = setInterval(clearSub, 1000);
function clearSub() {
AJS.$('#comment-issue').click(function () {
AJS.$("#footer-comment-button").hide();
var defaultRoleName = "All Users";
var customRoleSelected = false;
jQuery('#comment').live('focus', changeCommentLevel2);
jQuery('#commentLevel-suggestions').live('click', function()
{ customRoleSelected = false; });

});
AJS.$("#footer-comment-button").hide();
clearInterval(intervalID);
};

var defaultRoleName = "role:10010";
var customRoleSelected = false;

function changeCommentLevel()
{
var defaultRoleName = "role:10010";
if (customRoleSelected) return;
var commentLevelSelect = jQuery('.security-level select#commentLevel option[value="role:10010"]');
if (commentLevelSelect)
{ var labelText = commentLevelSelect.first().text(); 
jQuery("select#commentLevel").val("role:10010"); 
jQuery("#commentLevel-multi-select a.drop span.icon").removeClass("icon-unlocked").addClass("icon-locked"); 
var htmlEscapedLabel = AJS.$("<div/>").text(labelText).html(); 
jQuery(".security-level span.current-level").html(AJS.format(AJS.params.securityLevelViewableRestrictedTo, htmlEscapedLabel)); }

}

function changeCommentLevel2()
{
var defaultRoleName = "All Users";
if (customRoleSelected) return;
var commentLevelSelect = jQuery('.security-level select#commentLevel option[value="All Users"]');
if (commentLevelSelect)
{ 
jQuery("select#commentLevel").val("All Users");
jQuery("#commentLevel-multi-select a.drop span.icon").removeClass("icon-locked").addClass("icon-unlocked"); 
jQuery(".security-level span.current-level").html(AJS.params.securityLevelViewableByAll); }

}


AJS.$("#action_id_161").click(function () {

var defaultRoleName = "role:10010";
var customRoleSelected = false;
jQuery('#comment').live('focus', changeCommentLevel);
jQuery('#commentLevel-suggestions').live('click', function()
{ customRoleSelected = true; });

});

AJS.$('#footer-comment-issue').click(function () {

AJS.$("#footer-comment-button").hide();
var defaultRoleName = "All Users";
var customRoleSelected = false;
jQuery('#comment').live('focus', changeCommentLevel2);
jQuery('#commentLevel-suggestions').live('click', function()
{ customRoleSelected = false; });

});
jQuery('#issue-comment-add-cancel').live('click', function(){ customRoleSelected = false; });
});

</script>
<style>
.alertHeader
{display:none;}</style>

IT Support October 21, 2013

Did you ever resolve this? It's precisely the type of thing I wish to do currently!

0 votes
RambanamP
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.
October 9, 2013

can you share your javascript ? so i will try to help you!!

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events