Script runner -- questions about issue link validation within workflow transitions.

Bryan Karsh
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.
February 13, 2014

Hi all,

Had a couple questions with script runner. I know (and use) transition validation scripts like the example below:

issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate')

..but how can I require that the link also be limited to a specific issue type? Such as 'Bug'?

My other question is that I've noticed that the transition validation example above works fine if the link is set earlier in the workflow. *However* -- if the transition that has the validation script also has a transition screen with an issue link field, and the user uses that field, the validation script doesn't notice it, and prevents progression in the workflow. Ideally I'd like to make it so the user can add the required field if necessary with in the transition screen itself without backing out and trying the transition again.

Would the solution be to set up a behavior? Guessing I could use same validation script above?

Any tips appreciated!!

1 answer

1 vote
Henning Tietgens
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.
February 16, 2014

You can get the issuetype of the linked issue like this

issueLink.destinationObject.issueTypeObject.name

issueLink is one entry of the list you get from getOutwardLinks().

For your second question look here: https://answers.atlassian.com/questions/139592/check-for-duplicates-link-in-groovy-transition-validation-script

Henning

Tej March 12, 2017

How to validate a confluence link? 

Henning Tietgens
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.
March 13, 2017

Not sure what you mean by "validate", but you can get those links via the RemoteIssueLinkService. E.g.

remoteIssueLinkService.getRemoteIssueLinksForIssue(user, issue)?.remoteIssueLinks

to get all remote issue links of an issue.

Henning

Tej March 13, 2017

I want to check at least one confluence page is linked to an issue wiki page link.png

Henning Tietgens
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.
March 14, 2017

If you know the pageid of the Confluence page (–> select Page Information menu item and take a look at the URL) you could use following method.

boolean hasRemoteConfluenceLink(ApplicationUser user, Issue issue, String pageId, Logger log = null) {
    def conf_link = applicationLinkService.getApplicationLinks(ConfluenceApplicationType)?.first()
    if (!conf_link) {
        log?.error "No confluence application link found."
        return false
    }
    def globalId = "appId=$conf_link.id&pageId=$pageId"
    return remoteIssueLinkService.getRemoteIssueLinksForIssue(user, issue)?.remoteIssueLinks?.globalId?.contains(globalId)
}

Henning

Tej March 14, 2017

Thank a lot for response, 

But I want a global script just asking for a link of confluence or web link.

Is there any other way like below script... so that it throws an error and should ask for the link.

because we just can't do every confluence page id and keep on updating the script.

issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate')

Thanks

Henning Tietgens
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.
March 14, 2017

Yes, if you take a look into the API you could see there are some methods to get information from a RemoteIssueLink, e.g. getApplicationType() which should return "com.atlassian.confluence" (or better RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE) for confluence links. Using this the method from above could be adapted to check for any Confluence link.

import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger

static boolean hasAnyRemoteConfluenceLink(ApplicationUser user, Issue issue, Logger log = null) {
    def applicationLinkService = ComponentAccessor.getComponent(ApplicationLinkService)
    def remoteIssueLinkService = ComponentAccessor.getComponent(RemoteIssueLinkService)
    def conf_link = applicationLinkService.getApplicationLinks(ConfluenceApplicationType)?.first()
    if (!conf_link) {
        log?.error "No confluence application link found."
        return false
    }
    return remoteIssueLinkService.getRemoteIssueLinksForIssue(user, issue)?.remoteIssueLinks?.any{it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE}
}

hasAnyRemoteConfluenceLink(ComponentAccessor.jiraAuthenticationContext?.loggedInUser, issue)

(Not tested, take care of this by yourself. Please be aware that this takes the current user into consideration and what this user is able to see.)

Henning

Like Marina_M likes this
Kevin Seery October 5, 2017

Hi,

 

I'm trying to find a script that returns the a confluence link if contain 'closure report'.

Could this script be adapted todo this?

 

Many Thanks

Kevin

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events