Hi Team,
I am trying to update select list custom field Value( List) based on other custom field value selection using listeners in scrip runner.
For Example: If i select Custom field A and the Value is B Then Custom field C Value should be updated as D by using the Listeners in scrip runner.
Can any one help on the same.
Thanks,
CH Vamsi
Hi @Piyush A (STR) I have used the below code to set the value in one of the custom field but not able to set. can you please help me on the same.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
IssueManager im = ComponentAccessor.getIssueManager()
MutableIssue issue = im.getIssueObject("HSYS-5318")
if (issue){
//Get the value
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_XXX")
def cFieldvalue = issue.getCustomFieldValue(cField)
if ( cFieldvalue != "Devices"){
def customFieldManagerPL = ComponentAccessor.getCustomFieldManager()
def cFieldPL = customFieldManagerPL.getCustomFieldObject("customfield_XXX")
def cFieldvaluePL = issue.getCustomFieldValue(cFieldPL)
log.warn("Current parent Link ---" + cFieldvaluePL)
final customFieldName = 'Parent Link'
final isu = 'HSYS-5318'
final newValue = 'SFLS-889 CC-ART: Tender Insights within Portfolio'
def issu = ComponentAccessor.issueManager.getIssueByCurrentKey(isu)
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issu).findByName(customFieldName)
def availableOptions = ComponentAccessor.optionsManager.getOptions(customField.getRelevantConfig(issu))
def optionToSet = availableOptions.find { it.value == newValue }
customField.updateValue(null, issu, new ModifiedValue(issue.getCustomFieldValue(customField), optionToSet), new DefaultIssueChangeHolder())
//cFieldvaluePL.updateValue(null, issue , new ModifiedValue(cFieldValue, 'Test'))
//cFieldPL.updateValue(null, issue, new ModifiedValue(cFieldvaluePL, "new DefaultIssueChangeHolder"))
}
//Update the Value
//def changeHolder = new DefaultIssueChangeHolder()
//cField.updateValue(null, issue new ModifiedValue(cFieldValue, "Test"))
log.warn("Portfolio value is ---- " +cFieldvalue)
}else {
return "Issue doesn't exist"
}
Welcome to the community. !!
Add the below code to the listeners for Issue Update and Create. You may try to add new conditions or changes according to your needs.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.Issue
// the name of the custom field (single select list type)
final customFieldNameA = 'Select List CF'
final customFieldNameB = 'Select List CF B'
// the value of the new option to set
final newValue = 'D'
final exValue = 'A'
Issue issue = event.issue
def issueKey = issue.key
log.warn(issueKey)
assert issue: "Could not find issue with key $issueKey"
def customFieldA = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(customFieldNameA)
assert customFieldA: "Could not find custom field with name $customFieldNameA"
def customFieldB = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(customFieldNameB)
assert customFieldB: "Could not find custom field with name $customFieldNameB"
if(issue.getCustomFieldValue(customFieldA).toString() == 'A' && issue.getCustomFieldValue(customFieldB) == null ){
def availableOptions = ComponentAccessor.optionsManager.getOptions(customFieldB.getRelevantConfig(issue))
def optionToSet = availableOptions.find { it.value == newValue }
assert optionToSet: "Could not find option with value $newValue. Available options are ${availableOptions*.value.join(",")}"
customFieldB.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customFieldB), optionToSet), new DefaultIssueChangeHolder())
}
Also, on the create screen itself you can make the auto changes using Behaviour.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Piyush A (STR) ,
In my case the parent link in the portfolio custom field .. can any one help ime seting the value in this custom field .with REST API
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.
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.
Welcome to the community.
Do you have Automation for Jira add-on? If yes, you can simply define a rule for this scenario. For sure, it is possible via Script Runner. But you should be familiar with scripting. You can look at sample codes in community.
Also take a look at: https://scriptrunner.adaptavist.com/latest/jira/listeners.html
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.