Hi All,
I am trying to call JETI from scriptrunner. therefore I want to use the OSGi component described here: https://metainf.atlassian.net/wiki/spaces/PLUG/pages/66093062/API+-+Integration+with+other+services
Unfortunately I am not getting it to work with my code:
import com.atlassian.jira.ComponentManager;
import com.atlassian.plugin.PluginAccessor;
ComponentManager componentManager = ComponentManager.getInstance();
PluginAccessor pluginAccessor = componentManager.getPluginAccessor();
Class emailServiceClass = pluginAccessor.getClassLoader().findClass("com.metainf.jira.plugin.emailissue.api.EmailService");
def emailService = componentManager.getOSGiComponentInstanceOfType(emailServiceClass);
Class emailDefinitionApiClass = pluginAccessor.getClassLoader().findClass("com.metainf.jira.plugin.emailissue.api.EmailDefinitionApi");
def emailDefinitionApi = componentManager.getOSGiComponentInstanceOfType(emailDefinitionApiClass);
emailDefinitionApi.issue = "XXX-123"
emailDefinitionApi.to = ["x@mycomp.local"]
try{
emailService.sendEmail(emailDefinitionApi);
}catch(Exception Ex){log.error(Ex.toString());}
versions:
JIRA 7.7
JSD 3.10.0
JETI 7.1.0.16
Scriptrunner 5.4.1
Hi,
use this code
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.metainf.jira.plugin.emailissue.api.EmailService
import com.metainf.jira.plugin.emailissue.api.EmailDefinitionApi
@WithPlugin("com.metainf.jira.plugin.emailissue")
@PluginModule
EmailService emailService
emailService =
ComponentAccessor.getOSGiComponentInstanceOfType(EmailService.class);
EmailDefinitionApi em = new EmailDefinitionApi()
em.issue = "your issuekey"
em.to = ["your@mail"]
try{
emailService.sendEmail(em)
}catch(Exception Ex){
log.error(Ex.toString());
}
I'm getting this error - my be because I'm using a valuation license?
regards, s.
java.lang.NoClassDefFoundError: com/metainf/jira/plugin/emailissue/api/EmailService
java.lang.NoClassDefFoundError: com/metainf/jira/plugin/emailissue/api/EmailService
at Script371.run(Script371.groovy:7) [?:?]
at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runScriptAndGetContext(ScriptRunnerImpl.groovy:176) [?:?]
at com.onresolve.scriptrunner.runner.ScriptRunner$runScriptAndGetContext$5.callCurrent(Unknown Source) [?:?]
at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runStringAsScript(ScriptRunnerImpl.groovy:165) [?:?]
at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript$6.call(Unknown Source) [?:?]
at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate.doScript(CustomScriptDelegate.groovy:70) [?:?]
at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate$doScript$3.call(Unknown Source) [?:?]
at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction.doScript(CustomScriptFunction.groovy:46) [?:?]
Caused by: java.lang.ClassNotFoundException: com.metainf.jira.plugin.emailissue.api.EmailService
... 8 more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK - Decompiling the JETI-JAR made it clear how to use the API. I Succeeded using following code:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.metainf.jira.plugin.emailissue.api.EmailService
import com.metainf.jira.plugin.emailissue.api.EmailDefinitionApi
import com.metainf.jira.plugin.emailissue.action.EmailOptions
// https://scriptrunner.adaptavist.com/5.3.28/jira/scripting-other-plugins.html
@WithPlugin("com.metainf.jira.plugin.emailissue") // Addon App Key
@PluginModule
EmailService emailService
emailService = ComponentAccessor.getOSGiComponentInstanceOfType(EmailService.class);
EmailDefinitionApi em = new EmailDefinitionApi()
em.issue = "BD-145" // hard codiert zu Testzwecken
em.to = ["cf:customfield_11401"]
em.cc = ["tester04.sbg.ac.at@outlook.de"]
em.emailSubject = "Das ist ein Email-Test über die JETI API gesendet"
em.emailBody = "Das ist der Inhalt der Email... 2ter Test"
em.addAttachments = "ALL"
em.emailTemplate = "1" // Alle Kommentare
em.emailOptions = new EmailOptions()
em.emailOptions.setAddToWatchers(false)
em.emailOptions.setReplyToMe(false)
em.emailOptions.setMailAsMe(false)
em.emailOptions.setAddComments(false)
em.emailOptions.setSuppressCommentEvent(true)
em.emailOptions.setEmailFormat("html")
em.emailOptions.setCommentVisibility("g:jira-administrators")
em.emailOptions.setRichHtml(true)
try{
emailService.sendEmail(em)
}catch(Exception Ex){
log.error(Ex.toString());
}
regards, s.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stefan.
What does it mean?
em.emailTemplate = "1"
I've tried to set for this option the Template id from table AO_544E33_TEMPLATE, but I always get emails based on default template. I've tried to set a template name - result is the same.
Best regards!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vytautas Chamutovskij , so did I :o)
I've opened an request at META-INF and think they are fixing the issue - for now the Request has not been closed and is still in the status "under devlopement".
jfyi
regards,
stefan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Stefan! Say please the number of your request - I'll watch it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can try to use the WithPlugin and PluginModule annotations as it is written here:
https://scriptrunner.adaptavist.com/5.3.28/jira/scripting-other-plugins.html
Make sure that the service, which you try to inject is exported as public service. Also log the value of the service. You must make sure, that the service was successfully imported.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Alexey,
thank you for your answer. I wans't able to get it to work and I reverted to do a REST call :-S. Which is a workaround and not a solution for me.
Kind regards,
Matt
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.