Forums

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

how can i run background queries using customfield values?

C_ Faysal
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.
October 31, 2012

Hi.
i want to build something equal like the SEN field in support.atlassian.com
my goal is..

if a user enters a number in a field...some queries should be done on an external server using this number.
the results should be displayed below this field...

i think something like this is used to verify a customers SEN.

2 answers

1 accepted

1 vote
Answer accepted
francis
Atlassian Partner
November 7, 2012

You should use the script runner plugin.

The code would look like

import groovy.sql.Sql;
import groovy.sql.GroovyRowResult;
import java.sql.SQLException;

Sql connection;


try {
connection = Sql.newInstance( 'jdbc:postgresql://localhost:5432/database','user','password', 'org.postgresql.Driver' );
} catch (SQLException e) {
return "Unknown (Issue connecting to the database: ${e.getMessage()})";
}


GroovyRowResult result = null;
try {
    result = connection.firstRow("select name from customers where id = ${customerid} ");
} catch (SQLException e) {
    return "Issue retrieving data from the database: " + e.getMessage();;
}





if (result == null) {
   // no value given
   return "Customer not known";
}

return "The customer is " + result.get("name");

C_ Faysal
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.
November 8, 2012

hmm

i get some result like:

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: username for class: Script24 A stacktrace has been logged.

in my case i've set up a field "username"

by entering a user name a query should be performed to show me the users email_address

running the query in the local db works fine. am i missing something here?

francis
Atlassian Partner
November 8, 2012

Its hard to tell without code
Propably you use something like $username without declaring it.

You need to retrieve the value from the customfield. The script runner wiki has many examples how to do this.

Francis

0 votes
Nic Brough -Adaptavist-
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.
November 7, 2012

You'll need to do a bit of coding to get this. I've not seen a plugin that will do this off-the-shelf.

C_ Faysal
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.
November 7, 2012

yeah that's what i expected. but could you share any idea?

i mean i don't think it is done by some jelly scripts doesn't it

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events