Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,460,050
Community Members
 
Community Events
176
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

Atlassian Community Events