I have a validator that's supposed to do a check for
NOT Reopen Link Type
then
NOT [Base Link Type and Fix Version is Not Empty]
and if those conditions don't apply, then allow the transition without mandatory fields filled out.
It's running for only the first condition, not the second. It's not failing - just not running.
import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.link.IssueLinkManager; import com.atlassian.jira.issue.IssueFieldConstants; import com.atlassian.jira.issue.fields.IssueLinksSystemField; import com.opensymphony.workflow.InvalidInputException; import webwork.action.ActionContext; def issueLinkManager = ComponentAccessor.getIssueLinkManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def fixVersion= issue.getFixVersions() def fields = [] def fieldManager = ComponentAccessor.getFieldManager() def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemField def request = ActionContext.getRequest() if (request) { def params = request.getParameterMap() def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue // If issue is not REOPENED LINK TYPE, make all sorts of validations if ( !issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Reopen') && !issueLinkManager.getInwardLinks(issue.getId())*.issueLinkType.name.contains('Reopen')) { fields.addAll(['BA Actual Hours', 'BA Analysis By', 'Bug Source', 'Complexity', 'Data Fix', 'Dev Estimate Hrs', 'QA Estimate Hrs', 'RCA Categories - BA', 'Release Notes', 'Stat Code Impact']) fields.each { CustomField cf = customFieldManager.getCustomFieldObjectByName(it) if (cf && !issue.getCustomFieldValue(cf)) { if (invalidInputException) invalidInputException.addError(cf.id, "Value missing!") else invalidInputException = new InvalidInputException(cf.id, "Value missing!") } } if (invalidInputException) invalidInputException.addError("The fields marked below must be filled before analysis is completed.") }; else // If issue is not BASE LINK TYPE, and FIXVERSION is not NULL, make all sorts of validations if ( !issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Ticket') & ! fixVersion == null && !issueLinkManager.getInwardLinks(issue.getId())*.issueLinkType.name.contains('Ticket') & ! fixVersion == null) { fields.addAll(['BA Actual Hours', 'BA Analysis By', 'Bug Source', 'Complexity', 'Data Fix', 'Dev Estimate Hrs', 'QA Estimate Hrs', 'RCA Categories - BA', 'Release Notes', 'Stat Code Impact']) fields.each { CustomField cf = customFieldManager.getCustomFieldObjectByName(it) if (cf && !issue.getCustomFieldValue(cf)) { if (invalidInputException) invalidInputException.addError(cf.id, "Value missing!") else invalidInputException = new InvalidInputException(cf.id, "Value missing!") } } if (invalidInputException) invalidInputException.addError("The fields marked below must be filled before analysis is completed.") } else return true }
Well, back to this again. It seems to not be working for link type, I'm not sure if it's working on the second condition of project key since it's not skipping fields for Base issue type or for Reopen.
import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.link.IssueLinkManager; import com.atlassian.jira.issue.IssueFieldConstants; import com.atlassian.jira.issue.fields.IssueLinksSystemField; import com.opensymphony.workflow.InvalidInputException; import webwork.action.ActionContext; def issueLinkManager = ComponentAccessor.getIssueLinkManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def fixVersion = issue.getFixVersions() def fields = [] def fieldManager = ComponentAccessor.getFieldManager() def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemField def request = ActionContext.getRequest() if (request) { def params = request.getParameterMap() def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue // If issue is not REOPENED LINK TYPE, make all sorts of validations if ( (! issueLinkManager.getLinkCollectionOverrideSecurity(issue)?.linkTypes?.find {it.name.contains("Reopen")})) { fields.addAll(['BA Actual Hours', 'BA Analysis By', 'Bug Source', 'Complexity', 'Data Fix', 'Dev Estimate Hrs', 'QA Estimate Hrs', 'RCA Categories - BA', 'Release Notes', 'Stat Code Impact']) fields.each { CustomField cf = customFieldManager.getCustomFieldObjectByName(it) if (cf && !issue.getCustomFieldValue(cf)) { if (invalidInputException) invalidInputException.addError(cf.id, "Value missing!") else invalidInputException = new InvalidInputException(cf.id, "Value missing!") } } if (invalidInputException) invalidInputException.addError("The fields marked below must be filled before analysis is completed.") }; else // If issue is not BASE LINK TYPE, and PROJECT is not BASE, make all sorts of validations if ( (! issueLinkManager.getLinkCollectionOverrideSecurity(issue)?.linkTypes?.find {it.name.contains("Base")} & ! (issue.projectObject.key in ['BOPT', 'CAT', 'CPPT', 'WCT', 'POLT', 'PAUTOT', 'HOMET']))) { fields.addAll(['BA Actual Hours', 'BA Analysis By', 'Bug Source', 'Complexity', 'Data Fix', 'Dev Estimate Hrs', 'QA Estimate Hrs', 'RCA Categories - BA', 'Release Notes', 'Stat Code Impact']) fields.each { CustomField cf = customFieldManager.getCustomFieldObjectByName(it) if (cf && !issue.getCustomFieldValue(cf)) { if (invalidInputException) invalidInputException.addError(cf.id, "Value missing!") else invalidInputException = new InvalidInputException(cf.id, "Value missing!") } } if (invalidInputException) invalidInputException.addError("The fields marked below must be filled before analysis is completed.") } else return true } import org.apache.log4j.Logger import org.apache.log4j.Level def log = Logger.getLogger("com.acme.ValidateLinks") log.setLevel(Level.DEBUG) log.debug "foo bar"
Hi Lacey,
I would suggest to try and break your conditions into small in order to be easier for you (and me) to debug it and maybe also stick some log.debug messages in order to see where it goes.
Two observations in your second condition you have twice
! fixVersion == null
which can be replaced by one
fixVersion
And also instead of checking bot inward and outward links you can check it there is a link type of a specific name. something like
issueLinkManager.getLinkCollectionOverrideSecurity(issue)?.linkTypes?.find {it.name.contains("Ticket")}
regards, Thanos
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.
Removing this as the thread is getting confusing (they really should allow for deletions...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I now have a much bigger problem. It looks like we have been having background failures of a previously operational link validator. I opened a support ticket for it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I gave up and opened another support case. I can't get this to work and my deadline is the end of this week.
https://productsupport.adaptavist.com/servicedesk/customer/portal/2/SRJSUP-2075
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.