How to check if issue is mentioned in the Confluence page.

Chaya January 23, 2025

 

Confuence links are shown as "mentioned in" links in Jira issue. I want to restrict the workflow transition if the issue does not have "mentioned in" link with its issue key in the link. 

 

3 answers

1 accepted

0 votes
Answer accepted
Kawan Diogo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2025

Hi @Chaya 

 

Usually Confluence links are recognize in jira as Remote Links, with this you can create a Scriptrunner Validator looking in the issue if it has some remote link nominate as Confluence and also look in the summary if have the issue key reference.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

// Get the current issue
Issue issue = issue

// Get the RemoteIssueLinkManager to fetch remote links
def remoteIssueLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)

// Fetch all remote links for the current issue
List<RemoteIssueLink> remoteLinks = remoteIssueLinkManager.getRemoteIssueLinksForIssue(issue)

// Check if any remote link is of type "mentioned in" and contains the issue key
def hasMentionedInLink = remoteLinks.any { remoteLink ->
remoteLink.applicationName == "Confluence" &&
remoteLink.title?.contains(issue.key)
}

if (!hasMentionedInLink) {
// Block the transition if no valid "mentioned in" link is found
return false
}

// Allow the transition if a valid "mentioned in" link exists
return true

 

Let me know if this helps you.

 

Best Regards 

Chaya January 24, 2025

@Kawan Diogo it works

Like Kawan Diogo likes this
0 votes
Kawan Diogo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2025

Hello @Chaya 

 

Usually confluence links are recognized as "Remote Links", you can create a Scriptrunner Validator to block the transition according your condition.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

// Get the current issue
Issue issue = issue

// Get the RemoteIssueLinkManager to fetch remote links
def remoteIssueLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)

// Fetch all remote links for the current issue
List<RemoteIssueLink> remoteLinks = remoteIssueLinkManager.getRemoteIssueLinksForIssue(issue)

// Check if any remote link is of type "mentioned in" and contains the issue key, this second condition is optional, because the issuekey can be mentioned on the body of the page in confluence
def hasMentionedInLink = remoteLinks.any { remoteLink ->
remoteLink.applicationName == "Confluence" &&
remoteLink.title?.contains(issue.key)
}

if (!hasMentionedInLink) {
// Block the transition if no valid "mentioned in" link is found
return false
}

// Allow the transition if a valid "mentioned in" link exists
return true

 

Let me know if this helps you.

 

Best Regards.

0 votes
Anshul Arora
Contributor
January 23, 2025

Hi Chaya,

 

You can try Advanced Compare Condition in automations. Check if the issue contains a "mentioned in" link using JQL or custom data. 

 

 

Unfortunately, there is no built-in validator in Workflows for checking "mentioned in" links directly, so you need to use custom scripting or an add-on like ScriptRunner for Jira.

Script for the Validator:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

// Get all the issue links for the current issue
def links = issueLinkManager.getOutwardLinks(issue.id)

// Check if any link is of the type "mentioned in"
def hasMentionedInLink = links.any { link ->
link.issueLinkType.name == "mentioned in" && link.destinationObject.key.contains(issue.key)
}

if (!hasMentionedInLink) {
return false // Block transition
}
return true // Allow transition

 

Suggest an answer

Log in or Sign up to answer