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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Behaviour plugin to restrict linkedissue types

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

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

For example:

links.setFieldOptions(["duplicates":"duplicates"])

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!

Updated. Thanks Niclas.

 

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?

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

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>""")

 

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

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.

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.

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.

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.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you