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

Error in ScriptRunner workflow post function - Fast-track transition an issue "java.lang.String cannot be cast to java.util.Collection]"

Manjunatha K R March 22, 2017

Hi,

I am getting the below ERROR, in my

Fast-track transition an issue post function - but same is working in my older version JIRA 6.7.x before JIRA upgrade was done. Now I am using the below s/w versions.

2017-03-23 13:10:28,519 ERROR [utils.WorkflowUtils]: Errors: {}
Error Messages: [Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB java.lang.String cannot be cast to java.util.Collection]
Start of logs truncated as they exceeded 300 lines.

 Adaptavist ScriptRunner for JIRA is 4.3.16 and JIRA s/w version is 7.2.7

 

Condition::

def cfds = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Defect Source'};
String cfdsv = issue.getCustomFieldValue(cfds);

cfValues['Defect Source']?.value == 'ITG' || cfValues['Defect Source']?.value == 'ITG-Traffic' || cfValues['Defect Source']?.value == 'MTG_TRAFFIC' || cfValues['Defect Source']?.value == 'ITG-Automation' || cfValues['Defect Source']?.value == 'Design Server' || cfValues['Defect Source']?.value == 'MTG' || cfValues['Defect Source']?.value == 'FOA' || cfValues['Defect Source']?.value == 'Requirements' || cfValues['Defect Source']?.value == 'System Engineering'

Action: Assign to Engineering (231)

 

2017-03-23 13:10:28,519 ERROR [utils.WorkflowUtils]: Errors: {}
Error Messages: [Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB java.lang.String cannot be cast to java.util.Collection]
Start of logs truncated as they exceeded 300 lines.

 

Due to which I am unable to create cloned issues and link it using another post function in my workflow.

Same works in my older version JIRA s/w. Please suggest what is causing this issue in new JIRA version used.

  • Manju

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2017

I suspect it might be the second line of your condition, but it looks more like an error in the script being run, which you've not given us. Custom field storage is a little different and scripts need to be adapted.

 

Manjunatha K R March 23, 2017

Nic,

In My Fast Track Transition condition, the below one line is good enough as I am not using cfds

and cfdsv values any more.

 

cfValues['Defect Source']?.value == 'ITG' || cfValues['Defect Source']?.value == 'ITG-Traffic' || cfValues['Defect Source']?.value == 'MTG_TRAFFIC' || cfValues['Defect Source']?.value == 'ITG-Automation' || cfValues['Defect Source']?.value == 'Design Server' || cfValues['Defect Source']?.value == 'MTG' || cfValues['Defect Source']?.value == 'FOA' || cfValues['Defect Source']?.value == 'Requirements' || cfValues['Defect Source']?.value == 'System Engineering'

But same line works fine in my older JIRA version i,e 6.7.16 with out any ERROR.

But now i am using 7.2.7 JIRA s/w version and started failing using the ERROR posted above...

  • Manju
Manjunatha K R March 23, 2017

Even I treid to change the condition as below::

cfValues['Defect Source']?.value in ["ITG", "ITG-Automation", "ITG-Traffic", "Design Server", "MTG_TRAFFIC"]

 

Still same error persists..

2017-03-23 13:10:28,519 ERROR [utils.WorkflowUtils]: Errors: {}
Error Messages: [Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB java.lang.String cannot be cast to java.util.Collection]
Start of logs truncated as they exceeded 300 lines.
Manjunatha K R March 23, 2017

For more details on "Defect Source" custom field:

Defect Source is of Select List (single choice) date type.

def componentCF1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")

def selectedComponents1 = issue.getCustomFieldValue(componentCF1)

 

newIssue.setCustomFieldValue(componentCF1, selectedComponents1)

 

is the above steps are right way to copy from parent issue to Cloned issue?

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2017

What is "defect source" - select or date?  It can't be both.  Although I think that is the problem, as select fields are not strings.

 

Manjunatha K R March 23, 2017

"defect source" is of Select List (single choice) date type with value such as ITG, SQ, MTR configured.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2017

Please, select list OR date?  Which is it?

Manjunatha K R March 23, 2017

select list

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2017

Ok, sorry, I should have been able to see that from the last post, but you kept repeating "date"

A select list does not return a string, that's why you're getting a "cast" error.  You need to convert the array it returns to a string before you can compare it with another string.

 

Manjunatha K R March 23, 2017

Do you mean cfValues['Defect Source']?.value will return a String value?

Manjunatha K R March 23, 2017

And one more thing is, the above shared condition script is implemented based on the below options present in the Jira/Script runner post function example:

Fast-track transition an issue ->

Has select list value equal to

cfValues['My Select List']?.value == 'My value'

 

But it was working in my previous JIRA version i,e 6.7.16

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2017

>Do you mean cfValues['Defect Source']?.value will return a String value?

No. It won't.  That's the point.

Manjunatha K R March 24, 2017

Nic,

I tried to re-write my Fast Track Transition condition to get the String value from my select list custom field and try to re-execute the one JIRA issue state transition. But same Error has been observed.

import com.atlassian.jira.component.ComponentAccessor

def componentCF1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")
String selectedComponents1 = issue.getCustomFieldValue(componentCF1)

log.info(selectedComponents1)

String optionToDS = ComponentAccessor.getOptionsManager().getOptions(componentCF1.getRelevantConfig(issue)).find {option -> option.value == selectedComponents1}

log.info(optionToDS)

//if(optionToDS == "ITG")

if(selectedComponents1 == "ITG")
return true
else
    return false

  • Manju
Manjunatha K R March 24, 2017

Even I tried::

if(optionToDS == "ITG")

return true

else return false

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2017

Again, options are not strings, and a select list does not return a string, that's why you're getting a "cast" error.

Manjunatha K R March 28, 2017

Hi Nic,

Based on your last comment, i,e "You need to convert the array it returns to a string before you can compare it with another string."

Was trying to convert "option" value (i,e for "Defect Source" - Single Select list data type) to array it returns to a string ... using my below script. But selectedvalues variable is updated as null value. But no errors in the script found after execution.

I am not getting, what is wrong in this script.....

 

def cascade6 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Defect Source")
 def cfVal6 = issue.getCustomFieldValue(cascade6)

 //List<Option> selectedvalues = (List<Option>) issue.getCustomFieldValue(cascade6);
 //log.info(selectedvalues)
 List<String> selectedIDs = new ArrayList<String>();
 
 List<Option> selectedvalues = (List<Option>) ComponentAccessor.getOptionsManager().getOptions(cascade6.getRelevantConfig(issue)).find {option -> option.value == cfVal6}

log.info(selectedvalues)
 
 if (selectedvalues != null)
 {
   for (Option option : selectedvalues)
   { 
       selectedIDs.add(option.getOptionId().toString()); 
 
       log.info(option.getOptionId().toString())
       log.info(option.getOptionId())
   }// for end
 }

 

As Defect Source is a single select list, max one option value will be chosen during my workflow transition based on the option, Fast Track Transition should succeed. 

Even though it's array, only option value should be copied as per the Defect Source data types used.

  • Manju
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 28, 2017

> max one option value will be chose

Yes, but it is still an option value in an array.  That's what cfVa16 is returning back to you.  You can't cast it to a string, you need to get the single option out of the array and get the name of the option out of that (or compare it with the options available without going through strings)

Looking at the line:

List<Option> selectedvalues = (List<Option>) ComponentAccessor.getOptionsManager().getOptions(cascade6.getRelevantConfig(issue)).find {option -> option.value == cfVal6}

 
cfVa16 is an array with an option in it.  option.value is (from memory) a string with the name of the option in it.  I would be tempted to meet in the middle - extract the single element from the field value (so cfVa16 contains an option) and then use { option -> option == cfVa16 }
Manjunatha K R March 28, 2017

Nic,

After changing to option -> option == cfVa16, I am getting the below ERROR now.

2017-03-28 17:08:19,251 ERROR [utils.ConditionUtils]: *************************************************************************************
2017-03-28 17:08:19,251 ERROR [utils.ConditionUtils]: Condition failed on issue: INT-7546, built-in script:com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.FasttrackTransition
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ITG' with class 'com.atlassian.jira.issue.customfields.option.LazyLoadedOption' to class 'java.util.List'
	at Script1979.run(Script1979.groovy:29)
  • Manju
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 28, 2017

Could you re-read the stuff I've said several times about arrays?

TAGS
AUG Leaders

Atlassian Community Events