Greetings -
I am having an issue creating a script in Behaviours that allows me to pass the pulldown list selected item to my new task I create under the same issue. See illustration below. Custom Field name is Accounting Category (its default is TBD) - I want to pass the Operating Expense choice.
Here is the screen shot of the behaviour set up.
Here is the full script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
def accountingCategory = getFieldById(getFieldChanged())
def accountingCategoryValue = accountingCategory.value
if (!accountingCategoryValue){
return
}
def accountingCategoryIssueKey = accountingCategoryValue.toString().tokenize(":").last()
def accountingCategoryIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(accountingCategoryIssueKey)
def selectListCustomField = ComponentAccessor.customFieldManager.getCustomFieldObjects(accountingCategoryIssue).findByName("Accounting Category")
// could not find custom field with name "Accounting Category" on the accounting issue - do nothing
if (!selectListCustomField) {
return
}
def selectListValue = (accountingCategoryIssue.getCustomFieldValue(selectListCustomField) as LazyLoadedOption)?.value
def optionId = ComponentAccessor.optionsManager.getOptions(selectListCustomField.getRelevantConfig(accountingCategoryIssue)).find { it.value == selectListValue}?.optionId
getFieldByName("Accounting Category").setFormValue(optionId)
any help would be greatly appreciated.
Hello Steve,
Were you able to solve your issue following Adaptavist recommendations?
You can use the post function in this article as a template for your need:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.FieldManager
// the name of the field whose value we want to copy from parent to subtask
final String fieldNameToCopy = "Component/s"
FieldManager fieldManager = ComponentAccessor.fieldManager
if (!issue.isSubTask()) {
return
}
def fieldToCopy = fieldManager.allAvailableNavigableFields.find { it.name == fieldNameToCopy }
if (!fieldToCopy) {
log.info "Could not find field with name $fieldNameToCopy"
return
}
def parentIssue = issue.parentObject
def fieldToCopyId = fieldToCopy.id
switch (fieldToCopyId) {
case fieldManager.&isCustomFieldId:
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(fieldToCopyId)
def linkedIssueCustomFieldValue = parentIssue.getCustomFieldValue(customField)
issue.setCustomFieldValue(customField, linkedIssueCustomFieldValue)
break
case IssueFieldConstants.COMPONENTS:
issue.setComponent(parentIssue.components)
break
case IssueFieldConstants.FIX_FOR_VERSIONS:
issue.setFixVersions(parentIssue.fixVersions)
break
case IssueFieldConstants.AFFECTED_VERSIONS:
issue.setAffectedVersions(parentIssue.affectedVersions)
break
default:
issue[fieldToCopyId] = parentIssue[fieldToCopyId]
}
Let me know if this information helps.
how are you triggering the new task creation?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Either the pulldown create new sub-task or click the plus sign in the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
instead of behavior you should try using a Issue Create/Update Listener to copy the value from the Parent to the Sub-Task.
Behaviors are loaded on the current form, so might have to write additional code to get the issue context where the creation is triggered.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am new in customization Jira with the adaptavist plugins. So I need to do a listener instead of behaviours?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
here is how it will look
also you get get some solution here : https://library.adaptavist.com/entity/create-a-sub-task-when-parent-issue-has-a-specific-label
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After talking with Adaptavist - they told me to use a behaviour instead of a listener - so Not sure how to proceed here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
They are the experts. I would follow their inputs and they should have script samples too.
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.