Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,296,437
Community Members
 
Community Events
165
Community Groups

How display a message when sub-task is created?

Hi Community,

Is it possible to display a message when a sub-task is created? Let me give some context. I configured task workflow so that once task status gets closed a sub-task gets created. We have a purchasing project, Initially, a task gets created by the user, they attach quotes and require documents to the task and after review from purchasing team, it goes to leadership for approval. Once it gets approved by leadership and the task gets assigned back to the reporter, once the user clicks the "place order" transition, the task resolution is set to Resolved, and a sub-task gets created automatically.

Most of the users won't notice the default popup that a sub-task is created so they keep attaching invoices etc to closed tasks and causing confusion. I'm looking to have a more visible popup or a message that users can see it. It'll be great to display the sub-task issue key as well.

Is it possible to display a message on the parent task when a sub-task is created?

Thank you for your help.

1 answer

1 accepted

1 vote
Answer accepted

I think you can make use of ScriptRunner's listener. Listen to issue created event, check if it is a subtask, if so, update the parent accordingly. 

e.g. You can use a label to display the message. 

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

log.warn("Issue: " + event.issue)
if (event.issue.isSubTask()) {
    log.warn("Is subtask, parent: " + event.issue.parentObject)
    MutableIssue parent = ComponentAccessor.getIssueManager().getIssueObject(event.issue.parentObject.id)
    // Here I simply update parent's description
parent.setDescription(
"Subtask created: " + event.issue.summary)
// Save it as current user
    JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext()
    ApplicationUser user = authContext.getLoggedInUser()
    ComponentAccessor.getIssueManager().updateIssue(user, parent, EventDispatchOption.ISSUE_UPDATED, false)
}

 

It is not displaying an alert. It replaces the parent issue description with "Subtask created: summary(subtask issue summary)". I thought of displaying an alert on the screen when a sub-task is created.

That's just an example of how to listen to subtask created event.

You will have to find your preferred way of displaying a message. 

With Cloud it is not supported, see this thread: https://community.atlassian.com/t5/Jira-questions/JIRA-CLOUD-How-to-send-custom-Alerts-UserMessageUtil-for-Cloud/qaq-p/1756724 

If not Cloud, then that same thread mentioned UserMessageUtil class. You can find threads about it easily enough.

Failing both, you can use a field to display the message. 

Like Shah Baloch likes this

I tried UserMessageUtil, and there are two issues I'm facing, first I have to refresh the page in order to see the message, and the second problem is it displays four pop-up messages instead of one. Any idea how can I fix these two issues?

import com.onresolve.scriptrunner.runner.util.UserMessageUtil

UserMessageUtil.success("This issue has been closed and a sub-task has been created for further process, please attach invovices to the sub-task. Sub-task can be found below.")

message_05122022.jpg

Thank you for your help.

You are right, UserMessageUtil does not show the message unless the page is refreshed... but for your case, it should.

The create transition in the workflow has a post function to fire "Issue Created" event for listeners to catch, and afterwards the transition will refresh the page. 

Are you somehow creating subtasks without triggering the workflow transition?

 

As for the message repeating, I haven't been able to reproduce it. Try checking the logs on the listener to see if the listener got fired multiple times for the same issue?

Like Shah Baloch likes this

You are right, I was creating sub-task manually. It works if an auto sub-task gets created. I updated the text color and size to make it more visible. One thing I'm unable to make work is the hyperlink for the issue key. Issue key displays but it's not clickable. Any idea?

Here is the script

 

import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.event.issue.IssueEvent

if (issue.issueTypeObject.name == "Sub-task") {

UserMessageUtil.success("<h3 style='color:red;'><b>This Issue has been closed and a sub-task has been created for further process, please attach invovices to the sub-task. Sub-task can be found below.</b></h3>"
+ issue.key)
}

message_05132022.JPG

Thank you for your help

You need to use the <a> tag to create a hyperlink: 

UserMessageUtil.success("<h3 style='color:red;'><b>This Issue has been closed and a sub-task has been created for further process, please attach invovices to the sub-task. Sub-task can be found below.</b></h3>"
+ "<a href='link to issue here'>" + issue.key + "</a>")
Like # people like this

Thank you @KC Wong I was trying hyperlink but I was not including those plus (+) signs at beginning and end of the hyperlink so that's why it didn't work. I followed your steps and it works. I'm adding the final version below for those who don't have coding experience like me.

UserMessageUtil.success("<h3 style='color:red;'><b>This Issue has been closed and a sub-task has been created for further process, please attach invovices to the sub-task. Sub-task can be found below.</b></h3>"
+ "<a href='https://myjira.com/browes/$issue'>" + issue.key + "</a>")
 
One last question, is there a way to include the parent issue key in the popup? Like I add " This issue NA-60 (parent issue key) has been closed". Is that possible?

Thank you so much for your help!

issue.parentObject.key

Like Shah Baloch likes this

Thank you so much for your help.

I just started Jira development this month. So it's good learning experience for me too. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

319 views 0 10
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you