Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,939
Community Members
 
Community Events
165
Community Groups

Scriptrunner Script to update a custom field value to match another customer field value on event

Edited

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)

1 answer

1 accepted

0 votes
Answer accepted

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)

Antoine Berry Community Leader Mar 25, 2022

My bad, I forgot to add the customFieldManager definition. I updated the script in my first answer.

@Antoine Berry I cant thank you enough, that worked!

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

310 views 0 9
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you