How to add validation for "Issue" which is right below the "Linked Issues" field?

Hi, 

I wanted to check the linking issue has a correct custom field value.

i.e. I have custom field 'Feature Type' and values "Product Feature" and "Technical Feature" on the linking issue and now I want to validate this issue on the other issue which going to link and contain Product Feature or not.

Example: Test112.PNG

On the create screen, "GTN-28761" which is going link to another issue and I want to add validation that GTN-28761 has a value of Product Feature or not to show here (another issue create screen).

Thanks

2 comments

Tarun Sapra Community Champion Dec 06, 2017

In the validation phase of the create transition you will have to check if the custom fields have required values on the linked Issues or not.

How to fetch custom field value (since you already have issue Id of the linked issue thus you can get issue object using IssueManager)

https://community.atlassian.com/t5/Jira-questions/How-to-get-the-custom-field-value-using-by-groovy-script/qaq-p/385870

Code snippets to parse/get info of linked issues (answer form chris duffy)

https://community.atlassian.com/t5/Jira-questions/Validator-script-to-check-status-of-all-linked-issues-before/qaq-p/427966

Tarun Sapra Community Champion Dec 06, 2017

Also, the above samples work if you have script runner plugin installed.

Hi Tarun,

Thanks for your reply,

Yeah I have script runner plugin installed in my Jira.

Thanks

Hi Tarun,

Can you please help me to get linked issue custom field value?

I am getting confused there.

Thanks

Hi Tarun,

I tried this below code, did not work.

I'm a beginner for this Jira thing could you please help me.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import org.apache.log4j.Category
import com.atlassian.jira.issue.link.IssueLink;
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

IssueLinkManager linkMgr = ComponentAccessor.getIssueLinkManager()

def customFieldManager = ComponentAccessor.getCustomFieldManager()
//custom field of linking issue
def cField = customFieldManager.getCustomFieldObject("customfield_18815")

def cField1 = customFieldManager.getCustomFieldObject("customfield_18813")
def cFieldValue1 = issue.getCustomFieldValue(cField)

for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {


if ( (cFieldValue1.toString().contains("Product Feature")) && !(link.getSourceObject().getCustomFieldValue(cField).toString().contains("Product Feature")) ) {

invalidInputException = new InvalidInputException("Linked issue " + link.getSourceObject().getCustomFieldValue(cField) + " is not having right value")
throw invalidInputException
}


}

Comment

Log in or Sign up to comment
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

164 views 1 17
Join discussion

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