Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to create Structure pragmatically from script runner pluign

Akshatha July 8, 2019

As suggested in https://wiki.almworks.com/display/structure/Creating+a+New+Structure+Programmatically I am trying to create a new structure, if it doesnt exists via script runner (5.5.7). But I get below error 
"org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.almworks.jira.structure.AllPublicStructureComponents@16b28350' with class 'com.almworks.jira.structure.AllPublicStructureComponents' to class 'com.almworks.jira.structure.api.StructureComponents'"

Any clue on whats going wrong.

Script runner version : 5.5.7

Structure version 5.4.0

JIRA Server version 7.10.1

 

Thanks

1 answer

0 votes
Philip Heijkoop _ALM Works_
Atlassian Partner
July 25, 2019

Hi Akshatha,

 

I think you should try the following script:

 

import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.almworks.jira.structure.api.StructureComponents
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.almworks.jira.structure")

@PluginModule
StructureComponents structureComponents

// the name of the new structure
final String structureName = "YOUR_STRUCTURE_NAME"

def structureManager = structureComponents.structureManager

// if structure with the given name doesn't exist, create a new empty one
if (!structureManager.getStructuresByName(structureName, PermissionLevel.ADMIN)) {
structureManager.createStructure().setName(structureName).saveChanges()
}

 

Furthermore, I'd like to point you over to the Adaptavist Library, in particular the ScriptRunner and Structure section here. It should provide you with more curated examples. And otherwise they'd be happy to help if you file a support ticket.

 

Best,

Phil Heijkoop

Solutions Engineer

ALM Works

Andrej_Kapusta September 5, 2019

Hello,

I have same problem with my script:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.almworks.jira.structure.AllPublicStructureComponents@5ad942e8' with class 'com.almworks.jira.structure.AllPublicStructureComponents' to class 'com.almworks.jira.structure.api.StructureComponents'

and I am using recommended syntax:

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.StructureComponents
import org.apache.log4j.Level
import org.apache.log4j.Logger

@WithPlugin("com.almworks.jira.structure")

@PluginModule
StructureComponents sc

def log = Logger.getLogger("VALID_SCRIPT_issuesLinkedOnPpmIssue.groovy")
log.setLevel(Level.DEBUG)

...
...
...

 But this error is still showing. For example yesterday it worked and today again this error, even whn I didn't even touch script. Can you explain me how to avoid this error and work normally with StructureComponents? I am loosing my mind...

Philip Heijkoop _ALM Works_
Atlassian Partner
September 12, 2019

Hi Andrej,

Sorry you're getting this error. Can you tell me which versions of Jira, Structure and ScriptRunner you're on?

 

Alternatively, for more targeted help you can submit a support ticket either with us via support@almworks.com or at Adaptavist, depending on your exact needs.

 

Best,

Phil

Vitek Urban
Contributor
October 7, 2019

Hi Philip,

I am a colleague of Andrej, so I am well informed about this issue in our Jira environment.

We are using

  • Jira 8.1.2,
  • Script Runner 5.5.9.1-jira8
  • and Structure 5.6.0.

(Andrej also should submit a ticket on behalf of our client we are working for.)

I also tried to use

...
import com.almworks.jira.structure.AllPublicStructureComponents @PluginModule AllPublicStructureComponents structureComponents
...

But it did not work as well. Additionally, there is another error in the IDE while the class is not in the ...structure.api.* package under the appropriate Maven artifact).

 

Maybe this could help you: I have just realised that the script using the documented construction (the StructureComponents class) works fine from Script Console but not from a script saved to the scriptRoots.

Is there something special to set for using the scriptRoots for the Structure plugin???

Thank you very for help.

 

Best regards,

Vitek

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events