Use escalation service in Scriptrunner to copy a custom field value to another.

Hello

Scriptrunner has this very cool "escalation service", which basically runs after a certain interval (in minutes), executes a JQL and for each one of the issues returned executes a certain action.

Now of course most of the users will use this tool to execute a transaction; there are also many very good built-in scripts for the most used purposes, like leaving a comment or updating a field with a certain value.

This is all great, but I would need to achieve something one step further: I would like to copy a custom field value to another custom field.

The code that I have been using in the following:

def cField = customFieldManager.getCustomFieldObject("customfield_25401")
def cFieldValue = issue.getCustomFieldValue(cField)
issue.setCustomFieldValue('customfield_25407', cFieldValue)

However it returns an error

"No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (java.lang.String, com.atlassian.jira.issue.customfields.option.LazyLoadedOption)" [customfield_25407, XX] Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)"

 

I understand that the last line, is either using the wrong method or the arguments are not in the correct format.

Anybody able to help on this one?

 

Thanks a lot!

 

Mirco

 

 

 

 

 

1 answer

Hello Mirco, 

I believe this is due to groovy dynamic typing.I believe you need something like this:

def cField = customFieldManager.getCustomFieldObject("customfield_25401")
def cFieldValue = issue.getCustomFieldValue(cField as CustomField)
issue.setCustomFieldValue('customfield_25407', cFieldValue)

or something like this:

CustomField cField = customFieldManager.getCustomFieldObject("customfield_25401")
def cFieldValue = issue.getCustomFieldValue(cField)
issue.setCustomFieldValue('customfield_25407', cFieldValue)

 Please let me know if I can help you any further.

Cheers.

DYelamos

Hello Daniel

 

Thanks a lot for your time and for looking into this!

 

I tried both, but there is still something not working.

First script: just not working, seems to not understand what the previously defined "cField".

I am not familiar with the CustomField method, but it seems that either the argument is not understood (not the right class?) or the method is not known.

Sorry I am not a groovy expert, but may be the screenshot helps and it is easy for you or for someone to understand?

errpr2.png

 

 

Second script: similar error, but here it seems that the values are fetched correctly this time.error.png

If i understand correctly AS is a cool groovy keyword that changes types of objects. Does it help here to know the source field is a single-choice drop-down, and the target field is a multi choice? Normally the Scriptrunner "copy values to another field" script is able to do this without issues, but may be we need to convert the value of the source (string) in a value compatible for the target (array/object?)

 

Thanks again for the patience reading my attempted troubleshooting and many thanks in advance if anybody will be able to help further here.

 

have a nice friday!

 

 

 

 

 

 

 

You are missing the customfield import I believe:

take this:

import com.atlassian.jira.issue.fields.CustomField

CustomField cField = customFieldManager.getCustomFieldObject("customfield_25401")
def cFieldValue = issue.getCustomFieldValue(cField)
issue.setCustomFieldValue('customfield_25407', cFieldValue)

Does that work?

 

Thank you Daniel

 

This seems a huge progress.

However I think there is still the problem of the different type of fields.

Source field has a string as value, and target field has an object. (single choice drop-down vs multi choice)

The error this time reads

No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (java.lang.String, com.atlassian.jira.issue.customfields.option.LazyLoadedOption) values: [customfield_25407, RS] Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue()
 is applicable for argument types: (java.lang.String, com.atlassian.jira.issue.customfields.option.LazyLoadedOption) 
values: [customfield_25407, RS] Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), 
getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField) 

(sorry I had to paste this as code as the spam filter would block it otherwise)

I think this is not as basic as turning the object into string, is there an easy way to do it in groovy/jira?

Hello Mirco.

We have a few examples of this in our documentation, for example this link about validating multi selects.

I would advice some preparation before trying to get actual functionality running, going through a few examples and understanding them. 

Cheers!

Dyelamos

Awesome!

Thanks a lot Daniel, I will read everything and test with some examples

 

Have a nice weekend!

 

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

207 views 1 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you