Hi,
Trying to create a subtask using create a subtask postfunction by script runner in jira with a condition.
Condition: If a single select custom field is 'Yes' and same subtask type is not created yet then create a subtask
Was writing a condition for the same. But it is not working, any thoughts?
//cfValues['Is new hardware RQD?']?.value == 'Yes' &&
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField ishwrqd = customFieldManager.getCustomFieldObject("customfield_11604")
Option customFieldValue = (Option) issue.getCustomFieldValue(ishwrqd)
def customFieldValueRaw = customFieldValue.getValue()
if (customFieldValueRaw.equals("Yes"){
if(issue.isSubTask())
{
def issueParent = issue.getParentObject()
def parentSubTasks = issueParent.getSubTaskObjects()
def currentSubTaskType = issue.getissueType()
!parentSubTasks.find{it.getType() == currentSubTaskType}
}
}
Regards.
Hi @SysAdmin , here you have a functional script:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.issue.fields.CustomField CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() CustomField ishwrqd = customFieldManager.getCustomFieldObject("customfield_11604") Option customFieldValue = (Option) issue.getCustomFieldValue(ishwrqd) def customFieldValueRaw = customFieldValue.getValue() if (customFieldValueRaw.equals("Yes")) { if(issue.isSubTask()) { def issueParent = issue.getParentObject() def parentSubTasks = issueParent.getSubTaskObjects() def currentSubTaskType = issue.issueType !parentSubTasks.find{it.issueType == currentSubTaskType} } }
There were some error that I have fixed.
Thanks @Benito Jiménez _Sevidev_
For the correction.
But as per the use case I had to script it as below which is working
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
//def issue = Issues.getByKey('ABC-000')
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField ishwrqd = customFieldManager.getCustomFieldObject("customfield_Id")
Option customFieldValue = (Option) issue.getCustomFieldValue(ishwrqd)
def customFieldValueRaw = customFieldValue.getValue() as String
def found = true
if(customFieldValueRaw == "Yes"){
def sibling = issue.getSubTaskObjects()
if(sibling.size()>0){
for(Issue child:sibling){
log.warn "child"+child.getIssueType().getName()+"###"
if(child.getIssueType().getName()== "subtask name"){
found = false
}
}
} else if(sibling.size()==0){
return true
}
return found;
}
else{
return false
}
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.