Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Behaviour plugin to restrict linkedissue types

Jeff Pandinha March 14, 2017

Hello all,

Bear with me because I'm new to Jira, scriptrunner/behaviour plugin, groovy and Java. I'm trying to create a behaviour when user selects "Dupe" as resolution, Issue link field appears and is required. In addition, it would be ideal if the issuelink-type is restricted to "duplicates" and the issuelink-issue must not be empty. If not, a condition/validation check on the issuelink-type would do as well.

This is what I've got so far, the issue link hide/unhide works, but the restricting issuelink-type doesn't:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.InvalidInputException

def resolution = getFieldById("resolution")
def links = getFieldById("issuelinks")
def linkissue = getFieldById("issuelinks-issues")
def linktype = getFieldById("issuelink-types")
def res = resolution.getFormValue()
if (res == "3") {
    links.setReadOnly(false)
    links.setHidden(false)
    links.setRequired(true)
    def issueLinkManager = ComponentAccessor.getComponent(IssueLinkManager)
    def dupeoption = issueLinkManager.getOutwardLinks(underlyingIssue.getId()).find { it.issueLinkType.name == "duplicates" }*.id
    linktype.setFormValue(dupeoption)
    if (! linkissue.getFormValue()) {
        links.setHelpText("Must DUPLICATE another issue")
invalidInputException = new InvalidInputException("Linked Issue", "Linked Issue is required for Duplicate")
    }
}
else {
    links.setHelpText("")
    links.setRequired(false)
    links.setHidden(true)
}

Can anyone help shed some light into this? Is there something else I should use as linktype? There are entire classes for IssueLink such as DefaultIssueLinkTypeManager which I'm not sure whether to use or not. Thanks for any help on this.

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Evangelos Vrocharis July 28, 2017

This is done the same way as setting options. You simply need to set a map.

For example:

links.setFieldOptions(["duplicates":"duplicates"])
0 votes
Guilherme Nogueira
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 15, 2017

You can go through Javascript, remove certain link type from field value.

Do you know how to insert javascript into a JIRA screen using behavior?

Jeff Pandinha March 15, 2017

I'm afraid not yet. Where would be a good start to read about using javascript to manipulate JIRA screen behaviour?

Guilherme Nogueira
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 15, 2017

Yeah! this is a life safer smile

Try something like that:

getFieldById("SOMEFIELDINYOURSCREEN_ID").setHelpText("""<script>
$("#link-type option[value='causes']").remove();
</script>""")
getFieldById("SOMEFIELDINYOURSCREEN_ID").setHelpText("""<script>
$("#link-type option[value='causes']").remove();
</script>""")

 

Guilherme Nogueira
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 15, 2017

If you are using any version less than 7, it wont work cause jquery is not embedded

Jeff Pandinha March 15, 2017

Not quite working for me sad
Does the "SOMEFIELD.." can be any Field and not "issuelink-types"?
Also, it looks like a curly bracket is needed after $.
My behaviour looks like:

links.setHelpText("""&lt;script&gt;
${"#link-type option [value='causes']"}.remove();
&lt;/script&gt;""")

But "causes" is still listed. Also tried "#issuelink-type" in place of "#link-type" and "causes" still appears.

Running JIRA 7.3 and scriptrunner 4.3.16, btw.

Guilherme Nogueira
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 15, 2017

No no... yes I tested it using browser console... please change to it:

 

links.setHelpText("""&lt;script&gt;
\$("#link-type option[value='causes']").remove();
&lt;/script&gt;""")

Quando eu falo SOMEFIELDINYOURSCREEN_ID estou dizendo algum campo que esteja na sua tela, a tela que tem o campo para você fazer o link, provalmente links will work.

Jeff Pandinha March 15, 2017

Thanks Guilherme,

 I did some read up on javascript and jquery, the code:

links.setHelpText("""&lt;script&gt;
\$(\"#issuelinks-issuetype option[value='causes']\").remove();
&lt;/script&gt;""")

should work, as well as your example but unfortunately they don't.

Guilherme Nogueira
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 16, 2017

Well... sorry then.. for me, its working fine. Maybe JS is not executing in this field.

Maybe you can console.log('Testing blablabla');

If JS is working, the code that I sent to you will work (I tested here and worked).

If not, maybe problem is related to your mapping (field links is not working somehow) OR your original behavior mapping is wrong.

0 votes
Jeff Pandinha March 14, 2017

Updated. Thanks Niclas.

 

0 votes
Niclas Sandstroem
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

Update your question with the plugin in labels and I'm sure someone from Adaptavist will pop in and be able to answer your questions smile Good luck!

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events