I have a script that updates the custom field value of developer to match the issue assignee on all issue events and it works great.
I am trying to write a script that does something similar, but its not working (its also not failing, it just shows its not running at all) and I'm not sure which part I have wrong.
I am trying to update the custom field value of the field "cc date replacement" (12828) with the value of the custom field "cc date" (10522)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def issue = (MutableIssue) event.issue
def cc = ComponentAccessor.customFieldManager.getCustomFieldObject(10255) // "CC Date"
def datetimePickerField = ComponentAccessor.customFieldManager.getCustomFieldObject(12828) // "CC Date (Replacement)"
// Set the CC Date Replacement Field to be the same as CC Date
issue.setCustomFieldValue(datetimePickerField, issue.cc)
ComponentAccessor.issueManager.updateIssue(cc, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
here is the script that I based it off of that is working which updates the custom field of "developer" with the value of the issue assignee.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def issue = (MutableIssue) event.issue
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def userPickerField = ComponentAccessor.customFieldManager.getCustomFieldObject(10553) // Developer
// Set the User Picker to be the same as Assignee
issue.setCustomFieldValue(userPickerField, issue.assignee)
ComponentAccessor.issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Hello @Lexi ,
Please try this script snippet after updating with the correct custom field ids :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.MutableIssue
def issue = (MutableIssue) event.issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField1Id = 12400
def customField1 = customFieldManager.getCustomFieldObject(customField1Id)
def customField2Id = 12500
def customField2 = customFieldManager.getCustomFieldObject(customField2Id)
def customField1Value = issue.getCustomFieldValue(customField1)
def customField2Value = issue.getCustomFieldValue(customField2)
customField2.updateValue(null, issue, new ModifiedValue(customField2Value, customField1Value), new DefaultIssueChangeHolder())
Thank you @Antoine Berry !
That at least got it to run, but its failing.
Im not sure what I'm looking at here, but do you think its failing because the
Field 1 is a date field and Field 1 is a date/time field?
2022-03-25 12:26:03,850 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2022-03-25 12:26:03,850 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script33 at Script33.run(Script33.groovy:9)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My bad, I forgot to add the customFieldManager definition. I updated the script in my first answer.
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.