post function custom field if 'yes'status change 'b'if 'No"status change'a' and also to assign to respective team
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.workflow.TransitionOptions
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueService = ComponentAccessor.getIssueService()
def optionsManager = ComponentAccessor.getOptionsManager()
def currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def yesNoField = customFieldManager.getCustomFieldObject(12345L) // ID of the "yes/no" customField
def yesNoFieldValue = issue.getCustomFieldValue(yesNoField)
def teamCustomField = customFieldManager.getCustomFieldObject(12345L) // ID of the "Teams" custom Field
def cfConfig = teamCustomField.getRelevantConfig(issue)
def aTeam = optionsManager.getOptions(cfConfig)?.find { it.value.toString() == "A Team"} // Option name of the "A Team" in the "Teams" Custom Field
def bTeam = optionsManager.getOptions(cfConfig)?.find { it.value.toString() == "B Team"} // Option name of the "B Team" in the "Teams" Custom Field
def parameters = issueService.newIssueInputParameters()
def actionId
def transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()
def changeHolder = new DefaultIssueChangeHolder()
if (yesNoFieldValue.toString().equals("yes")) {
actionId = 111 // ID of the 'a' transition from the status I want
def result = issueService.validateTransition(currentUser, issue.id, actionId, parameters, transitionOptions)
if (result.isValid()) {
def issueResult = issueService.transition(currentUser, result)
if (!issueResult.isValid()) {
log.warn("Failed to transition ${issue.destinationObject.key}, errors: ${issueResult.errorCollection}")
} else {
issueResult
}
} else {
log.warn("Failed to transition ${issue.destinationObject.key}, errors: ${result.errorCollection}")
}
teamCustomField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(teamCustomField), aTeam), changeHolder)
} else if (yesNoFieldValue.toString().equals("no")){
actionId = 221 // ID of the 'b' transition from the status I want
def result = issueService.validateTransition(currentUser, issue.id, actionId, parameters, transitionOptions)
if (result.isValid()) {
def issueResult = issueService.transition(currentUser, result)
if (!issueResult.isValid()) {
log.warn("Failed to transition ${issue.destinationObject.key}, errors: ${issueResult.errorCollection}")
} else {
issueResult
}
} else {
log.warn("Failed to transition ${issue.destinationObject.key}, errors: ${result.errorCollection}")
}
teamCustomField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(teamCustomField), bTeam), changeHolder)
}
Hello, Rahul.Pardeshi@verscend.com and welcome to the Community!
Could you, please be more specific and describe the issue in more details? Unfortunately, it's quite hard to understand what exactly you're trying to achieve.
Looking forward to hearing from you soon!
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.