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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.")
Thank you for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
Thank you for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>")
Thank you so much for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.