Make "Issue Link" a required field is not being enforced

Janine Roe April 18, 2012

I set up a field configuration such that the "Issue Link" field is a required field for a specific type if issue. (What I'm trying to do is I created a "Test" type and I want to enforce that this issue type is linked to the Story(ies) it is testing).

I see that the drop down for Linked Issues is indeed requried. However the text field below it which lets you set the issue(s) is NOT required. There is always a default link type set, so in effect, you will have the Linked issue drop down type set (i.e. blocks, relates to etc), but it is not enforcing that you select an issue to link it to.

Is there a way to set both the Linked Issue drop down AND the issue field both to required? Or is there a way to check if that field is blank? There has to be a way to do that?


Thanks in advance.

4 answers

1 accepted

0 votes
Answer accepted
Peter Trubshaw June 19, 2012

Please note the value of 'Tests' in the following is actually the Name of the link (in issue linking), not the outward or inward description (ie. Not what you see on the ticket itself)

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

0 votes
Bert Dombrecht
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.
October 25, 2019

I realize this is an old post, but here in 2019, I was facing a similar issue as the original question: if a user transitions an issue to Closed with the 'Duplicate' resolution, I want the Linked Issue fields to be mandatory. I am doing this with a workflow validator, using Scriptrunner. My problem was indeed that the 'Linked Issues' field has a default, while the 'Issue' field (where you select an issue to link) is blank. The validator regarded this combination as not blank en thus proceeded with the transition.

This is how I got it to work:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.Issue;
import com.opensymphony.workflow.InvalidInputException

Boolean passesCondition = true;
def request = webwork.action.ActionContext.getRequest();

if (request) {

IssueLinkManager linkMgr = ComponentAccessor.getIssueLinkManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
// get Resolution
def resolution = issue.getResolution()?.getName();

// Validator
if (resolution == "Duplicate") {

// Check for outward links of type 'Duplicate'
def outwardDuplicates = linkMgr.getOutwardLinks(issue.getId())*.issueLinkType.name.contains("Duplicate");
// Check for inward links of type 'Duplicate'
def inwardDuplicates = linkMgr.getInwardLinks(issue.getId())*.issueLinkType.name.contains("Duplicate");
// Get formfields
String linkType = request.getParameter('issuelinks-linktype');
String[] linkedIssues = request.getParameterValues('issuelinks-issues');

if (outwardDuplicates || inwardDuplicates) {
passesCondition = true; // Issue already linked as Duplicate
} else if (linkType in ["duplicates", "is duplicated by"] && linkedIssues){
passesCondition = true; // Duplicate issue selected in form
} else {
passesCondition = false; // No issue linked as Duplicate
throw new InvalidInputException("Please link a duplicate issue.")
}
} else {
passesCondition = true;
}
}
return passesCondition; 
0 votes
alistairg February 23, 2015

This solution does not work when the script is set as a validator for the create transition.

set code to below:

import org.apache.log4j.Category
    import com.atlassian.jira.ComponentManager
    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.Issue
    import com.atlassian.jira.issue.IssueManager
    import com.atlassian.jira.issue.CustomFieldManager
    import com.atlassian.jira.issue.fields.CustomField
	import com.atlassian.jira.issue.link.IssueLink
	
	def Category log = Category.getInstance("com.oncreate.jira.groovy.ValidateFunction")
	log.setLevel(org.apache.log4j.Level.DEBUG)
	log.debug("id: " + issue.getId())
	
	log.debug(issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Root Cause'))
	return issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Root Cause')

and the logs generate "id: null" and false for the two log calls.

so obviously failing because the issue is not yet created...

could someone please confirm if there is a workaround to this or not for the create transition. i need this on create so having on another transition is not a valid solution for me (but might be for others of course).

Julien Benzimra August 13, 2015

I'm interested by this validator, and facing the same difficulties.

@Alister, Indeed the link is not yet created. The best we could do is to test the values entered in the linked issue field. Indeed, after the custom validators have been checked, the system still controls that the link can be created before executing the transition, so it's still secured.

Unfortunately, I can't figure out how to access the values of this field ("linked issue" and "link type")

Any idea ?

JamieA
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.
August 18, 2015
0 votes
Ramiro Pointis
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.
April 18, 2012

In which version of Jira are you working? Have you tried to add a condition on the workflow asking for the value field?

Ramiro Pointis
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.
April 18, 2012

Yep, that option is only for versions before the Jira 5. Maybe in a plugin? I'm investigating a little. Do you have a condition called 'Script Condition'?

Ramiro Pointis
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.
April 18, 2012

Ok, so you can install the Script Runner plugin. It adds a condition called 'Script Condition' and there you have the possibility to add a Built-In script to check blank fields or something like that. It's a very good plugin, I use it a lot.

It has this Built-In script for example: Has at least one outward duplicate link

Here is some documentation.

Janine Roe April 18, 2012

Version 5.0.1

I'm actually looking right now in the workflow at a condition for a transition, but I do not see an option for checking for a value field.

Janine Roe April 18, 2012

FYI, I just installed JIRA Suite Utitlites plug in and it does not have what I need.

Ramiro Pointis
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.
April 18, 2012

Happily, you won't have to code anything. In that Built-In that I indicated you just need to change the value of 'duplicated' to 'test' or other thing. The script is already built.

Hope you find the solution. And remember to mark the answer if it works.

Cheers!

Janine Roe April 19, 2012

Thanks Ramiro, I actually have Script Runner installed. I was hoping I didn't have to code up anything to get this to work. I'll have to look into it a bit more. Even if i do get this to work, I see that the Issue Links field is not available via Greenhopper. :(

Ramiro Pointis
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.
April 19, 2012

I'm not entirely sure. This is the script the condition uses:

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

@JamieEchlin, it is possible to do an 'If' clause or something like that?

Janine Roe April 19, 2012

Ramiro - thanks I'll try it out and let you know how it goes. Is it possible to perform this action only on certain issue types? I don't want this automatic linking to occur on all issues types, just my custom type "Test".

JamieA
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.
April 19, 2012

Yeah, you can put whatever script you like there... no constraints, eg:

if (issue.issueTypeObject.name == "Task") {
    return issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate')
}
else {
    return true
}

Janine Roe April 19, 2012

I don't mean to be obtuse about this, but it appears as if this script is only a once and done thing? Meaning it's only run on what every Issue ID you specify? Is that correct?

If this is the case, this is not what I'm looking for. What I need is a situation where whenever a sub-task (of type test) is created, it will automatically create a link to it's parent issue.

Ramiro Pointis
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.
April 19, 2012

Awesome, everyday I found new things on the plugin. @jroe with that your issue is completely resolve I think.

Ramiro Pointis
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.
April 19, 2012

If the issue type 'test' is a sub-task it will create the link automatically, because it is a sub-task of a parent issue.

In the case it isn't a sub-task, the workflow will validate that the issue has at least one issue linked everytime and every issue type that it is assigned to that workflow.

JamieA
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.
April 19, 2012

What Ramiro is suggesting I believe is that you use the simple scripted validator function from the script runner plugin, which you can put on the Create step or whatever. The "issue" in the script refers to the issue currently being entered.

This will enforce that there is one outward link of whatever type you need. You may need to experiment, or if I have the wrong end of the stick can you clarify what you are looking for.

Janine Roe April 19, 2012

Jamie & Ramiro -- I really appreciate you sticking with me and helping me out with this. The Script Runner tool is really helping me understand how to tap into Jira's functionality.

Here is where I am with things:

I created this snippet of code that is doing what I want. I tested it in Script Runner.

if (issue.issueTypeObject.name == "Sub-test") {
	issueLinkManager.createIssueLink (issue.getId(), issue.getParentId(), 10200, 0, issue.reporter);
        return true;
}

So now my question is, I don't know where to put this? I'm assuming I have to add it as a Post Function in the Create Issue step in the Workflow? If so, I don't see where I can put it? It's asking me to specify a path to the script and all I have is the above code. Is this where I'm supposed to put it? I'm hoping you can point me in the right direction for this.

Thanks for your help so far.

JamieA
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.
April 20, 2012

Hi Janine... can you explain again what you need to do? From your question I thought you wanted to validate there was a certain type of issue link for a certain issue type, but your code is creating a link.. and also creating it to its subtask, which I don't think you want. BTW I think you are getting there, we just need some more info...

Janine Roe April 20, 2012

Well, yes, my original question in this topic was that when I set the "Issue Links" field to be a required field when creating or editing certain issue types (tests and sub-tests), Jira was not validating if the link was set and referencing a Jira issue (it only checks to see if the link type drop down is set, but doesn't take into account the text field to enter the issue to link with.) (Which sounds like a bug to me)

So then it moved into the idea of using Script Runner to validate as part of a workflow. I guess in my mind, my solution shifted from "validating" to more "automating". Meaning, rather than check to see if the user created the link, just create the link behind the scenes. So I was thinking that during a "create issue" if the issue being created is of type "sub-test" (my custom type), then automatically link this sub-test to it's parent with my custom link, "Tests" (outward = tests , inward = is tested by). So that is what my above script is trying to do. However I really don't know where to put this.

I hope that makes some sense. Oh and I was thinking that this automating is only going to work for "sub-test" types, not "test" types (parent type issue).

JamieA
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.
April 20, 2012

I would just use the "create a subtask" built-in post-function on the Create step, then the user doesn't need to do anything, if you only want to create a subtask. If you want to create an issue link, that's possible, but it needs to know where to link to.

Janine Roe April 21, 2012

Hey Jamie,

Well I installed my own version of Jira on my local server so I can test my script out (I've wanted to do that anyway so I can develop my own plug in). Could you tell me where I would need to put the script on the my jira server so it will run as part of the post function? Does it matter where it goes? And would I name it with a .groovy extension? (This is all very new to me, so I'm sorry for the basic questions).

Ramiro Pointis
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.
April 22, 2012

Yes, I'm a little lost here. I thought you wanted to make a condition to validate that the issue has a linked issue. Now I'm not sure. But Jamie is right, you're almost there, and by your self too, that's a good thing :)

Janine Roe April 22, 2012

Ramiro and Jamie -- you are both being very patient with me, much appreciated. Let me step back to the original question I asked...adding validator check and Jamie's example of a solution:

if (issue.issueTypeObject.name == "Sub-test") {
    return issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Tests')
}
else {
    return true
}

I FINALLY saw what it is you were going for with this...AND I found in the workflow the place to put it. In the workflows, Create Issue under the Validators, I saw you can add a Script Validator and use the Simple Scripted Validator, which you can paste an embedded script in there and set what the error message is if it fails validaton as well as indicate what field to associate the error message.

So I did just that, plugged in the above code and tested it. However, what's happening is that it's always failing. And I *think* that the reason for this is that, it's looking for exising links? And on the Create, the link hasn't been created, but rather it's the form field to create I want to check to see if it's valued. Does that make sense? If I am completely wrong about this and it's not working for another reason, then let me know. Regardless, I'm not sure how to get this to work.

thanks again for all your help thus far.

Ramiro Pointis
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.
April 22, 2012

If I understood correctly, you are trying to insert this script in the 'Create' step, is this true? If that's the case it is showing error because when the issue is created doesn't have a issue linked yet. This script can be used for example in the case you want to make sure it has a linked issue before you would be able to 'Resolve' the issue. This script it is only to verify if the issue has a 'Tests' link to another issue but only in case when the issue type is 'Sub-test'.

JamieA
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.
April 22, 2012

That sounds plausible... Maybe best to put it as a condition of the outward transitions from open? It should be possible to get the link even though it's not committed yet, I will have a dig around.

Vishnukumar Vasudevan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 12, 2013

@Jamie Echlin,

Thanks a lot for such a wonderful plugin. I also use it, big fan J.

Was trying to make the field ‘Issue Links’ mandatory on the create issue step.

Tried the below script :

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

This doesn’t work as it checks for already created links, not good to use in Create step L.

Could you suggest any work around ? FYI, I use JIRA 5.1.3.

Thanks, Vishnu.

Shinjani Gaur March 28, 2014

Is there a way to validate that the "Cloners" link does NOT exist and proceed with issue creation if it doesn't exist?

Radim Drinka April 8, 2015

@Jamie Echlin [Adaptavist] , @Vishnu - I am struggling with the same problem as Vishnu. It is crutial for us that Linked Issues is a required field. We work with JIRA 6.3.9. Any help? Thanks, Radim

Deleted user September 1, 2016

@Jamie Echlin [Adaptavist] - I'am facing the same problem.

The validator "“issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('incorporates') “"

is not working on create transition. We want to force the user to enter value (actually link some issue to the issue being created) for linked issues field upon creation.

We are on JIRA v6.4.4

Thank you!

JamieA
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.
September 8, 2016

Suggest an answer

Log in or Sign up to answer