simple script in not working in workflow validator

J Manas Kumar July 7, 2020

Hi All

 

Need your help on this script.

i am trying to validate a condition where, i have a issue "XYZ" , and under that issue sub task is there.

when i am trying to add another issue "PP"  to "XYZ" , i need to put a validator on create screen, that if the sub task is in certain status and it  has specific values , then it should return false or true , and based on that the transition will happen. the problem is its going to desired if block but it still allowing the transition to happen. can anyone help me on this?

added the code below.


import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor ;
//import com.atlassian.jira.issue.MutableIssue ;
//import com.atlassian.jira.issue.fields.config.FieldConfig ;
//import com.atlassian.jira.issue.customfields.option.Options ;
//import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Level ;
import org.apache.log4j.Logger ;

def logs = Logger.getLogger("com.citi.jira.postFunction.BRParentLinkCheck")
logs.setLevel(Level.DEBUG);

logs.debug("Started Parent Link Verify For BR Changes : ----")

// Grab Current Issue
CustomFieldManager customFieldManager1 = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager();
def parentLinkField = customFieldManager1.getCustomFieldObjects(issue).find {it.name == "Parent Link"}
def parentLinkValue = issue.getCustomFieldValue(parentLinkField) as String
boolean pass = true

Issue PlanviewIssue = issueManager.getIssueObject("" + parentLinkValue);
//String planviewStatus = PlanviewIssue.getStatus().getName()
//def parentIssueName = PlanviewIssue.getIssueType().getName() as String
//logs.debug("printing parent Issue Name : ----" + parentIssueName)
if(parentLinkValue != null){
// if(PlanviewIssue.getIssueType().getName() == "Planview"){
logs.debug("Entering into if issue type is Planview Manas : - ---- - - - - - ")
def allSubTask = PlanviewIssue.getSubTaskObjects()
logs.debug("Prinitng All Sub tasks Under Planview On Create: ---" + allSubTask)
allSubTask.each{ i ->
logs.debug("Printing Sub Task Issue Under Planview -->>" + i.getIssueType().getName())
if(i.getIssueType().getName() == "Approval Sub-task"){

logs.debug("Printing Status For each Sub Task Issue Under Planview -->>" + i.getStatus().getName())
String status = i.getStatus().getName()
logs.debug("Status Printing :---" + status)
CustomField approval = customFieldManager.getCustomFieldObjects(i).find {it.name == "Approval type"}
String approve = i.getCustomFieldValue(approval) as String
logs.debug("Printing Approval type Field value : --->>" + approve)

if(status != "Open" && approve == "BR"){
logs.debug("Entering 1st if block : --->>")
return pass = false
logs.debug("Entering 1st if block pass value : --->>" + pass)
}else if(status == "Open" && approve == "BR"){
logs.debug("Entering else if block : --->>")
pass = true
}else{
logs.debug("Entering else block : --->>")
pass = false
}
}

else pass = false
logs.debug("Entering issue type else block : --->>")
logs.debug("Entering issue type else block : --->>" + pass)
return pass
}
}else return pass

/* }else if(parentLinkValue == null){
return pass
}*/

 

Any help will be appreciated

Regards

Manas

1 answer

0 votes
Italo Qualisoni [e-Core]
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.
July 7, 2020

Hi @J Manas Kumar ,

Take a quick look in your script but I wasn't sure what error you are having. You can share with us if is there any error in the last executions;

I notice this return statement where you are also attribute false to pass variable, I'm not sure if is this valid in Groovy.

return pass = false

 

Take a look in this example, here you will have a good approach to check for sibling subtasks and improve your code.

Simple Script Validator - Checking sibling subtasks

J Manas Kumar July 8, 2020

Hi @Italo Qualisoni [e-Core]  what i want is i want to go from one transition to another transition upon some certain conditions. like you have suggest , i have only returned true and false normally. it should be block the transition when its false , but it still allowing to create the other issue based on the condition, which should not happen.

 

let me know if you want more clarification.

 

 

regards

manas

Italo Qualisoni [e-Core]
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.
July 8, 2020

Hi @J Manas Kumar ,

I won't be able to provide the complete script due to lack of business logic and time, but I think you have all the information you need in that article I shared with you in my previous comment to start troubleshooting. Start  testing with a simpler version of the script and start incrementing it.

Suggest an answer

Log in or Sign up to answer