Hi All
I am trying to implement one Validator for Checking some Field Value On Create Screen using Custom Script Validator.
My requirement is to compare field value with the linked issue's field value which can be called as parent.
i have two issues, A and B, A has a values IA Field which contains 1,2,3.
When i will create issue B which has a field called "TA" it should contain only 1 or 2 or 3 , rather then this if i enter value 4 it should throw error.
the problem is its only checking first value or you can say single value , when i have added 1 in issue B its not throwing error and able to create but when i am creating issue "C" with value of 2 , it should able to create issue but its throwing error.
i have added logs and code blow please check and let me know if anyone can help.
//Written By Manas
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Level ;
import org.apache.log4j.Logger ;
import com.opensymphony.workflow.InvalidInputException
def logs = Logger.getLogger("com.jira.postFunction.DLDCheck")
logs.setLevel(Level.DEBUG)
logs.debug("Entering into dld and hld validator .>>>>>>>>>>>")
def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
ApplicationUser admin = userManager.getUserByName("INT_JIRA")
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
logs.debug("Printing issue Value For Impacted Apps :" + issue)
CustomField hldLink = customFieldManager.getCustomFieldObjects(issue).find {it.name == "HLD Link"}
String hldLinkValue = issue.getCustomFieldValue(hldLink) as String
logs.debug("Getting values of hldLinkValue field :-----" + hldLinkValue)
Issue hldIssue = issueManager.getIssueObject("" +hldLinkValue);
logs.debug("The HLD Issue associated to DLD is: "+ hldIssue)
CustomField imapctedApps = customFieldManager.getCustomFieldObjects(hldIssue).find {it.name == "Impacted Application/s"}
def imapctedAppsValue = hldIssue.getCustomFieldValue(imapctedApps) as String
logs.debug("Getting values of imapctedAppsValue field :-----" + imapctedAppsValue)
String[] impactedFieldArray = imapctedAppsValue.split(';')
logs.debug("Printing splited impacted array from HLD Level : --" + impactedFieldArray)
CustomField applicationNew = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Application New"}
logs.debug("checking what type of applicationNew field it it :-----" +applicationNew.getClass().getName())
Issue applicationNewValue = issue.getCustomFieldValue(applicationNew) as Issue
logs.debug("Getting values of applicationNewValue field :-----" + applicationNewValue)
def checkSummary = applicationNewValue.getSummary()
logs.debug("Getting values of checkSummary :-----" + checkSummary)
String checkSummary1 = checkSummary.trim()
logs.debug("Getting values of checkSummary1 :-----" + checkSummary1)
boolean pass = true
for(String str : impactedFieldArray){
String newValue = str.trim()
logs.debug("Printing newValue after removing spaces from IA : ------" + newValue)
if(checkSummary1.equals(newValue)){
logs.debug("in if Block newValye is : -----" + newValue)
logs.debug("in if Block check Summary1 is : -----" + checkSummary1)
logs.debug("in if Block true : -----")
pass
}else{
logs.debug("in else Block false : -----")
throw new InvalidInputException("Wrong HLD Link")
}
}
/*
if(Arrays.asList(impactedFieldArray).contains(checkSummary1)){
logs.debug("in if Block true : -----")
return true
}
else{
throw new InvalidInputException("Worng HLD Link")
logs.debug("in else Block false : -----")
}
*/
log report : ---
2020-07-22 11:51:12,901 DEBUG [postFunction.DLDCheck]: Entering into dld and hld validator .>>>>>>>>>>> 2020-07-22 11:51:12,901 DEBUG [postFunction.DLDCheck]: Printing issue Value For Impacted Apps :test 2020-07-22 11:51:12,910 DEBUG [postFunction.DLDCheck]: Getting values of hldLinkValue field :-----WD-6 2020-07-22 11:51:12,911 DEBUG [postFunction.DLDCheck]: The HLD Issue associated to DLD is: WD-6 2020-07-22 11:51:12,920 DEBUG [postFunction.DLDCheck]: Getting values of imapctedAppsValue field :-----154515 Sawgrass 2020-07-22 11:51:12,921 DEBUG [postFunction.DLDCheck]: Printing splited impacted array from HLD Level : --[154515 Sawgrass] 2020-07-22 11:51:12,925 DEBUG [postFunction.DLDCheck]: checking what type of applicationNew field it it :-----com.atlassian.jira.issue.fields.ImmutableCustomField 2020-07-22 11:51:12,925 DEBUG [postFunction.DLDCheck]: Getting values of applicationNewValue field :-----CSI-827 2020-07-22 11:51:12,925 DEBUG [postFunction.DLDCheck]: Getting values of checkSummary :-----154515 Sawgrass 2020-07-22 11:51:12,925 DEBUG [postFunction.DLDCheck]: Getting values of checkSummary1 :-----154515 Sawgrass 2020-07-22 11:51:12,926 DEBUG [postFunction.DLDCheck]: Printing newValue after removing spaces from IA : ------154515 Sawgrass 2020-07-22 11:51:12,926 DEBUG [postFunction.DLDCheck]: in if Block newValye is : -----154515 Sawgrass 2020-07-22 11:51:12,926 DEBUG [postFunction.DLDCheck]: in if Block check Summary1 is : -----154515 Sawgrass 2020-07-22 11:51:12,926 DEBUG [postFunction.DLDCheck]: in if Block true : -----
Regards
Manas