Hi,
I have a requirement where subtasks are supposed to be auto-created when a new parent is created in jira but the catch is that a single line text field(name) and assignee on the sub-task must be populated from a confluence page table with key value mappings. So if there are 10 rows then 10 sub-tasks should be created.
Name Assignee
IRR bngda
ABC dlynch
I have scriptrunner for Jira but not for confluence so finding it difficult to approach a solution for this.
I have created sub-task using script post function create sub-task and additional issue actions for small automations but this i am not able to think as number of sub-tasks cannot be added in advance and will depend on confluence page table length.
We don;t want user to select Name and Assignee manually on a jira ticket so maintaining list in confluence and not via custom field in jira. But if there is an easy way to do this completely in jira also then it would be great. Also maintaining list in jira makes it easy for non admin users to manage it.
Any help guidance would be highly appreciated!
BR,
Bhupesh
While I can see Ravi's point, I'm not sure I completely agree.
I think having a confluence page as an easy place for users to maintain a list of values is a good approach in my opinion.
There are some limitations and possible complications to be aware of, but it's definitely better than hardcoding the key-value mapping and then requiring the jira admin to update frequently.
Here is a short script to get you started to get values from a table in a confluence page using application link authenticated request:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.applinks.JiraApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.sal.api.net.Request
import org.jsoup.Jsoup
def pageId=35241928 //put your own page ID here
def appLink = ComponentAccessor.getComponent(JiraApplicationLinkService).getPrimaryApplicationLink(ConfluenceApplicationType)
def conflUrl = appLink?.displayUrl
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
def pageUrl = "$conflUrl/rest/api/content/$pageId?expand=body.storage"
def request = applicationLinkRequestFactory.createRequest(Request.MethodType.GET, pageUrl )
def response = request.execute()
def soup = Jsoup.parse(response)
def map = soup.select('table')[0].select('tr').tail().collectEntries{row->
[(row.childNodes[0]):(row.childNodes[1])]
}
Some assumptions:
That's a great script. My only concern was that it relies on Confluence page to exist with a specific table, which is can be tricky sometimes to control because people can edit the page easily.
Thanks for sharing this, Jsoup is a great for parsing.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the great help!
So all my key value pairs are in this map and then i need to create a script listener which will run the sub-task creation code inside a loop till the length of this map field? Or maybe a custom script post function inside parent create transition with sub-task creation code inside a loop. How would you suggest me to create the sub-tasks ?
I also need to figure out the code for sub-task creation as out of box create sub-task script runner post function can't be utilized for this requirement, or am i wrong in saying this?
Thank you again for the guidance :) you are helping me convert a requirement which i initially thought may not be possible to implement.
BR,
Bhupesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think if you can use a post function, that's probably more specific than a listener.
But you are correct, the built-in create sub-task feature can't be used as-is.
You need to script the sub-task creation from scratch
map.each{key, value ->
//code to create subtask
}
You can borrow code for creating subtasks from the library: https://library.adaptavist.com/entity/create-a-sub-task-and-link-to-parent-issue-in-jira
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It worked like a charm, but there is one small issue and it's with jsoup parsing , the key value pairs are having the table descriptor tags associated with them like this <td>IRR</td> <td>bngda</td>
i tried to do a bit research but couldn't find a way to get rid of the tags, do you know how can i get rid of them?
Thanka alot again :)
BR,
Bhupesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this is how the page is store on confluence
<table class="wrapped">
<colgroup>
<col/>
<col/>
</colgroup>
<tbody>
<tr>
<th>Application Name</th>
<th>Application Owner</th>
</tr>
<tr>
<td>IRR</td>
<td>bngda</td>
</tr>
<tr>
<td>RISK</td>
<td>dlynch</td>
</tr>
<tr>
<td>FRR</td>
<td>drdovan</td>
</tr>
</tbody>
</table>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a jsoup implementation that's more explicit and will get the text elements of each column:
def map = soup.select('table')[0].select('tr').tail().collectEntries{row->
def cols = row.select('td')
[(cols[0].text()):cols[1].text()]
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well using Confluence page to store these key-value mapping is also not the best approach IMO.
Since you have ScriptRunner, you can always access your Confluence page (using application link or REST API) and parse that table where you have that key-value mapping. Technically it is possible but relying on a table stored in Confluence to update an Issue in Jira is probably adding too much complexity to your automation.
Doing it entirely from Confluence might be easier though using a macro to call Jira REST API.
I hope it helps.
Ravi
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.