How can I find jira issues that are linkes to a specific Confluence page?

We have User Stories specified in Confluence and the corresponding development and testing acitivities managed in JIRA. They are linked via the "Wiki page" link that supports linking any JIRA issue with a Confluence page. We would like to show all related JIRA issues on the Confluence page itself using the JIRA issues macro, which allows specifiny a JQL to find the issues to present.

Is there a way to find all these related JIRA issues with JQL?

I was thinking there should be a way to search links via their values, but no luck. We also have the JQL Tricks plugin, which doesn't help here, it seems.

2 answers

1 accepted

OK, I found a way, using the suggestion script runner plugin by C.Feysal. Thanks very much mate!

Here's the code in the getQuery method of the scripted JQL function (you essentially put any SQL statement there that returns issue ids) - I called it "linkedToPage"

Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {   
	ComponentManager componentManager = ComponentManager.getInstance()
	def delegator = (DelegatorInterface) componentManager.getComponentInstanceOfType(DelegatorInterface.class)
	String helperName = delegator.getGroupHelperName("default");

	def sqlStmt = """select issueid from remotelink where url = 'https://YOUR_CONFLUENCE_DOMAIN/pages/viewpage.action?pageId=""" + operand.args[0] + """'"""

	Connection conn = ConnectionFactory.getConnection(helperName);
	Sql sql = new Sql(conn)
	def booleanQuery = new BooleanQuery()
	sql.eachRow(sqlStmt) {
                booleanQuery.add(new TermQuery(new Term("issue_id", "${it.issueid}")), BooleanClause.Occur.SHOULD)
	}
	return booleanQuery
}

i never tried so this is only a guess...but with script runner plugin you can extend your jql to sth like

maybe the "hasLinks" will be what you desire?

regards

Thanks for the quick reply, but I don't think this would work. This functionality is similar what the JQL Tricks plugin provides, which is searching by link type.

In this case I need the link value. Further to that, based on the JIRA DB these types of links are not regular links. They are implemented as remote link, which may mean they have a different way of retrieving them. Not sure about that, though...

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

767 views 2 19
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you