Hi - I rely on Scriptrunner advanced filters for certain dashboards and Jira boards. However it appears the sync has stopped working, and I now need to manually sync the filter in order to see any results on my jira dashboard.
Try this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
// import com.atlassian.jira.event.type.EventDispatchOption
// import com.atlassian.jira.user.ApplicationUsers
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfCustomerJob = customFieldManager.getCustomFieldObjectByName("CustomerJob")
log.error "cfCustomerJob: $cfCustomerJob"
def cfCustomerJobValue = issue.getCustomFieldValue(cfCustomerJob)
log.error "cfCustomerJobValue: $cfCustomerJobValue"
if (cfCustomerJobValue[0].toString().equals("ABC"))
{
log.error "cfCustomerJobValue[0].toString().equals(\"ABC\") is true"
OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
Option option = optionsManager.getOptions(cfCustomerJob.getRelevantConfig(issue)).getOptionForValue("XYZ", null);
log.error "Found option: $option"
issue.setCustomFieldValue(cfCustomerJob,[option])
// issueManager.updateIssue(ApplicationUsers.toDirectoryUser(ComponentAccessor.jiraAuthenticationContext.getUser()), issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
My guess is you're using the script as a postfunction. Maybe you have to uncomment the commented lines and use this as the last postfunction in the list of postfunction to work. This is for JIRA 6. I added some log errors you should see in the log file. If everything is fine you can change the methods to log.debug. Or you could start with log.debug and set the log level accordingly.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
have you checked this for post function ,.... I think it is not working
ComponentAccessor.jiraAuthenticationContext.getUser() returns ofBiz while only ApplicationUser are allowed in ApplicationUsers.toDirectoryUser()
Thanks,
Sumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Depends on the jira version...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add some logging... log.warn(option) etc. Otherwise you can't know what's not working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What type of field is "CustomerJob"? Are you sure you are hitting the if? If it is a single select box, then I don't believe you can use array coding, the value is a list of Options.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is a multi select field. With that said, it will only ever have one selected value. It should have been configured as a single select field during implementation, but it was mistakingly not. It is my understanding the only way to change its type is to either update the DB directly, or do some sort of mass export/import (into a new single select field). But for now, it will likely remain as is.
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.