How to use enum in ScriptRunner script?

Pawel Wanago March 22, 2016

Hi,

I am trying to pass enum to function, but it stil raises errors:

import com.atlassian.jira.component.ComponentAccessor
def plugin = ComponentAccessor.getPluginAccessor().getPlugin('com.almworks.jira.structure')
// Get structure with ID 119
def syncManager = plugin.getModuleDescriptor('sync-manager').getModule()
syncManager.resync(114, SyncDirection.INBOUND, false)

I mean SyncDirection.INBOUND here, API where I found it is available here: http://almworks.com/structure/javadoc/latest/com/almworks/jira/structure/api/sync/SyncDirection.html

It still raises me:

groovy.lang.MissingPropertyException: No such property: SyncDirection for class: Script1
	at Script1.run(Script1.groovy:6)

1 answer

0 votes
Aleks Yenin (Polontech)
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.
March 22, 2016

Hm.. Maybe import will resolve the problem?

import com.almworks.jira.structure.api.sync.SyncDirection;
JamieA
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.
March 22, 2016

Yes, you will need the import, and @WithPlugin (https://scriptrunner.adaptavist.com/latest/jira/scripting-other-plugins.html#__withplugin) so the classloader can find it. I think it would be better to use @PluginModule (same page) rather than your method.

 

Pawel Wanago March 22, 2016

I tried it too, also with @WithPlugin it raises:

unable to resolve class com.almworks.jira.structure.api.sync.SyncDirection

with code:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.sync.SyncDirection
//blah blah blah

also when I use just import com.almworks.jira.structure.

JamieA
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.
March 22, 2016

Did you put the right param for WithPlugin? See https://scriptrunner.adaptavist.com/latest/jira/scripting-other-plugins.html#_example. Please paste the full script that doesn't work, the blah blah is the important bit.

Pawel Wanago March 23, 2016

That's it:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.sync
import com.almworks.jira.structure.api.sync.SyncDirection
@WithPlugin("com.almworks.jira.structure")

@PluginModule
StructureSyncManager syncManager
syncManager.resync(114, SyncDirection.INBOUND, false)

I'd like to run one direction sync.

JamieA
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.
March 23, 2016

It's missing imports, this works for me:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.almworks.jira.structure.api.sync.SyncDirection
import com.almworks.jira.structure.api.sync.StructureSyncManager

@WithPlugin("com.almworks.jira.structure")
@PluginModule
StructureSyncManager syncManager

syncManager.resync(114L, SyncDirection.INBOUND, false)
Pawel Wanago March 23, 2016

Oh, thanks, that helped! Is it possible to run this code periodically? Every 5 minutes or something?

JamieA
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.
March 23, 2016
Pawel Wanago March 23, 2016

Thank you very much.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events