Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

post function custom field if 'yes'status change 'b'if 'No"status change'a'

Rahul.Pardeshi@verscend.com
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 29, 2018

post function custom field if 'yes'status change 'b'if 'No"status change'a'  and also to assign to respective team 

2 answers

0 votes
Atlassian Tecnofor August 29, 2018
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)
}

 

0 votes
Grigory Salnikov
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.
August 29, 2018

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!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events