Hi All,
I have text field in Jira called 'Project'.. Likewise , I had a table in Confluence with one of columns as name 'Project' .
So, when users enter data in the field 'Project' it should validate the data in column from Confluence page .. If data in field 'Project' is not available in Confluence table column 'Project' ticket should not be created..
Any scripts or references are much appreciated.. Please reach back to me in case of unclear requirement so I can eloborate in detail..
Thanks,
Venkat
Hi Peter,
I was able to get Third Columns which is description in Confluence Table and not able to read the First Column 'Project'
Also, I was not able to insert these values into field in Jira
Your response is much appreciated
Thanks,
Venkata
Can you share a sample of what your page/table looks like in its storage format?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Peter for the response!
As per above Screenshot of Confluence Table.. We are looking to have Project Key(Test123, TEST456 etc..) into a Jira Field called "Project Key".. Either Scripted Field which populates data from Confluence or Workflow or Field Validator so when user enter data it should be text same as "Project Key" Column in Confluence Table else request/ticket should not be created.
Let me know if need any further information from my end
Thanks,
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 sample script that should get you started in the correct direction:
import groovy.json.JsonSlurper
import com.atlassian.jira.applinks.JiraApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.net.Request
import org.jsoup.Jsoup
def confluenceLink = ComponentAccessor.getComponent(JiraApplicationLinkService).getPrimaryApplicationLink(ConfluenceApplicationType)
def conflUrl = confluenceLink?.displayUrl
def pageId = 325059187 //put your own
def request = confluenceLink.createAuthenticatedRequestFactory().createRequest(Request.MethodType.GET, "$conflUrl/rest/api/content/$pageId?expand=body.storage")
def pageJson = request.execute() as String
def pageBody = new JsonSlurper().parseText(pageJson)['body']['storage']['value'] as String
def doc = Jsoup.parse(pageBody)
def table = doc.select('table')[0]
def headers = table.select('th').collect{it.text()}
def rows = table.select('tr').drop(1).collect{row->
def rowMap =[:]
row.select('td').eachWithIndex{col, i->
rowMap[headers[i]] = col.text()
}
rowMap
}
def testProject = 'AAABC'
def projectColHeader = 'Project'
assert testProject in rows.collect{it[projectColHeader]}
This will
From there, you should be able to find other references for how to get your project field and use that to compare against the extracted table data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Seeing your table screenshot, I replicated your table.
Viewing the storage format of that page would still be helpful in cases there is other xml that might interfere with the jsoup parsing.
Here is what happen on my instance after I re-created a page that looks like yours:
Here is a successful result
And here is a failure result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Peter,
Is it possible to provide your email address? Also, let me which one are you using Workflow validator for the field or Scripted Field.? How to clear the error that "Assertion Failed"
Let me know if I am missing anything
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm only using the console as a means of doing a proof of concept.
You asked for sample scripts and references. I gave you a sample script that can read a table from a confluence page.
You will have to do some work on your side to understand what the script is doing and modify it according to your business case. and integrate it with your workflow.
If you are not able to make those modifications you should hire someone that can. Implementing a script supplied from a forum without understanding what it does and being able to manipulate it is a dangerous proposition.
I share my groovy knowledge voluntarily. It's not part of my job. So no, I will not be sharing my email address.
As for helping you further, I've requested a sample of the storage format of your confluence page twice. Knowing exactly what the text in the page looks like is critical to being able to parse the content correctly.
The fact that your assert statement is returning a bunch of null values tells me that either 1) the column header is not exactly "Project Key" (perhaps there are some extra space or other non-printing characters) or 2) the Project Key column is not actually aligned directly above the project key values (perhaps because of some merged cells).
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.