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

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

This widget could not be displayed.
Henning Tietgens Community Champion Feb 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

How to validate a confluence link? 

Henning Tietgens Community Champion Mar 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

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

Henning Tietgens Community Champion Mar 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

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 Community Champion Mar 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

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted 5 hours ago in Europe

Topic Tuesday: How did you learn about the AUG programme?

Back in 2010 I hadn't been using the Atlassian tools (JIRA, Confluence, Bamboo) that long and I started searching online to see if I could chat to other users primarily about how they used the produc...

13 views 0 0
View post

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