I have a custom cascading field called support group and every time this field is changed I want it to change the assignee to a specific user based on the new option. I could use this same idea for many different things. So is it possible to run a script when this value is changed, not on a transition, and not on every save?
Community moderators have prevented the ability to post new answers.
Hi Cole,
you can use a listener for an issue updated event and then with in your script you can check which field is changed and do something.
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Name of custom field"} if (change) { // do something log.debug "Value before update : ${change.oldstring}" log.debug "Value after update : ${change.newstring}" } else { // something changed but is not the custom field with name 'Name of custom field' so do nothing... }
What is the "ChildChangeItem"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's just an implementation detail - each one represents a single change to an issue. The code Thanos gave you shows how to see if a particular field changed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I don't need to change that to match something on my end?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will need to use your custom field's name to match your's, unless is named 'Name of custom field'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Right. Just wanted to make sure "ChildChangeValue" wasn't something I needed to fill in as well.
Going to try something like this with my field values. I will report back after testing.
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Name of custom field"} if (change) { // do something def optionsManager = ComponentAccessor.getOptionsManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def fieldName = "testCascadingSelectList" def field = getFieldByName(fieldName) def customField = customFieldManager.getCustomFieldObjectByName(fieldName) def fieldConfig = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(fieldConfig) def parentOption = options.find {it.value == "A"} def childOption = parentOption?.childOptions?.find {it.value == "A1"} field.setFormValue([parentOption.optionId, childOption.optionId]) log.debug "Value before update : ${change.oldstring}" log.debug "Value after update : ${change.newstring}" } else { // something changed but is not the custom field with name 'Name of custom field' so do nothing... }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hey Cole,
hm I am afraid this is not going to work. The reason is that the script I provided you is for a ScriptRunner Listener but the script you pasted uses a Behaviour.
You can do it with both ways. But have a look in behaviours limitations and choose wisely.
Please let me know if you need further assistance.
regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So what would you recommend for me? I just combined your script with a cascading select list script. I am not too familiar with Listener vs Behaviour.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's easiest to do this in a listener. A listener fires after the user submits the form. It will overwrite whatever value they have selected for the field, if any. It really depends what you want to achieve. Do you want to just set the value, or do you just want to default a value and let the user change it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am wanting to change the cascading field options when a certain field is changed to a certain value. Users will be able to change the cascading field after. This essentially moves the ticket from one teams queue to another team.
My logic: If "Procurement Status" = "Received" then set cascading field "Support Group" = ("Desktop","Support")
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.