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

mfabris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 22, 2017

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

0 votes
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2017

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

mfabris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2017

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!

 

 

 

 

 

 

 

Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2017

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?

 

mfabris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2017

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?

Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2017

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

mfabris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2017

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