Use JNDI connection with Groovy in Service Desk workflow

Hi,

I have a groovy script in the post function of the Create transition that connects to an external DB through JNDI using the below code.

import javax.naming.Context
import javax.naming.InitialContext
import javax.sql.DataSource
...
37> Context initContext = new InitialContext()
38> Context envContext = (Context)initContext.lookup("java:/comp/env")
39> DataSource ds = (DataSource)envContext.lookup("jdbc/MyDS")
....

It works perfectly if I create the issue using the normal JIRA interface.

But it gives me the below error when I create the issue from the Service Desk interface

...
/servicedesk/customer/portal/14/create/167 [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: PROJ-xyz, actionId: 1, file: 
/usr/local/jira/scripts/myscript.groovy
javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory 
[Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]
at myscript.run(myscript.groovy:37)
Caused by: java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory
at com.atlassian.plugins.rest.module.ChainingClassLoader.loadClass(ChainingClassLoader.java:65)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
... 1 more

Is this a compatibility issue between the Script Runner and Service Desk?

Thanks

Graziella

2 answers

This widget could not be displayed.

That code throws the same error when run through the script console, so although service desk seems to often cause problems, I don't see it's the cause this time.

What version of JIRA is it?

This widget could not be displayed.

JIRA 6.3.10, SD 2.3.3, Script Runner 3.0.9

I thought it was the SD given that if I open the issue through the normal interface the script works.

I use the same code in many other groovy scripts that I run in other workflows, and all of them works, the only difference here is the SD... !!

What do you think it can be the reason?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

578 views 25 15
Join discussion

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