How to use enum in ScriptRunner script?

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

This widget could not be displayed.

Hm.. Maybe import will resolve the problem?

import com.almworks.jira.structure.api.sync.SyncDirection;

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.

 

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.

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.

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.

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)

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

Thank you very much.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

504 views 3 18
Read article

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