Last Commented Date custom field

By in
Last Commented Date custom field

Today a use case from the admin’s life. The need is: a separate field that displays the date of the last comment added. You can find the solution in this post.

To complete the task, we will need the Power Scripts plug-in, and more precisely two of its elements: Simple Issue Language and SIL Listeners. For me, it is one of the most useful and satisfying add-ons. What exactly is Simple Issue Language? It is a para-language for scripting in Jira, greatly expanding its capabilities. We can use it to refer to most of the application`s objects, listen for user actions or schedule automatic script execution. SIL has quite good documentation, which I encourage you to read.

Last Commented Date is going to be a field that will be used in reports and jql filters, and will display the date of the last added comment. This kind of custom field (Last public comment date) is already available in Jira Cloud.

  1. Custom field creation
    1. in the Custom Fields section, add a new field of the Date Picker type
    2. (optional) set the appropriate context so the field will be available only for selected projects/issue types
    3. add a field on selected screens
    4. check the ID of the newly created field (in my case it`s 22501)
  2. SIL script creation
    1. open SIL Manager and write a script to be used in SIL Listeners mechanism
      if (project == "TEST") {
      string [] cmt = getLastComment (key);
      customfield_22501 = cmt [3];
      }
      

       

    2. getLastComment returns the table below, so the 3rd element will be the comment creation date (counting from 0). Full documentation here.

      Key name

      Description

      id Id of the issue comment.
      text Comment text.
      author Author of the comment.
      created Creation date, as string, can be assigned to a date variable.
      updatedBy Updater, or empty string if there is no updater.
      updated Updated date, or empty string if there’s no update.
      securityLevel Comment security level.
    3. Before we attach the function to SIL Listeners, we can check the result on a specific task and check what we get.
  3. Runing the SIL Listeners mechanism
    1. open the SIL Listeners section
    2. add a new listener and fill in the necessary fields
    3. to execute such scripts, I suggest using a dedicated user with adjusted permissions
    4. the synchronous option will make the script run in one thread with the event on which the mechanism is listening (Issue Commented), thanks to which it will be able to fill in the Last Commented Date field immediately

That’s it, I invite you to share your comments, experiences or doubts on contact [at] jiraforthepeople.com

Leave a reply

Your email address will not be published. Required fields are marked *