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.
Community moderators have prevented the ability to post new answers.
This is done the same way as setting options. You simply need to set a map.
For example:
links.setFieldOptions(["duplicates":"duplicates"])
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm afraid not yet. Where would be a good start to read about using javascript to manipulate JIRA screen behaviour?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah! this is a life safer
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>""")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you are using any version less than 7, it wont work cause jquery is not embedded
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not quite working for me
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("""<script> ${"#link-type option [value='causes']"}.remove(); </script>""")
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No no... yes I tested it using browser console... please change to it:
links.setHelpText("""<script> \$("#link-type option[value='causes']").remove(); </script>""")
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Guilherme,
I did some read up on javascript and jquery, the code:
links.setHelpText("""<script> \$(\"#issuelinks-issuetype option[value='causes']\").remove(); </script>""")
should work, as well as your example but unfortunately they don't.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 Good luck!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.