Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Problem automating query and emailing results

Richard Bone September 8, 2020

I have a requirement to email a list of all new Jira users on a weekly basis to our Training team so they can add Jira training to those users' training plans. To accomplish this task, I've created a Scriptrunner resource pointing to my local database and have created a Scriptrunner scheduled job using the partial script below. For some reason, the script only works if I don't include a 'where' clause in the select statement; obviously not acceptable. As soon as I do, I get an error indicating 'unexpected token : Imp @ line 4 column 87. I've tried this from the script console as well and got the same results.

import com.onresolve.scriptrunner.db.DatabaseUtil

def rows = DatabaseUtil.withSql('local') { sql ->
sql.rows('select id,customfieldtypekey,cfname from customfield where cfname like 'Imp%')}
def sqlTable = new StringBuffer()
sqlTable<<"""<table class="aui"><tr>"""
rows.first().keySet().each{
sqlTable<<"""<th>$it</th>"""
}
sqlTable<<"</tr>"
rows.each{ columns ->
sqlTable<<"<tr>"
columns.each{ cell ->
sqlTable<<"<td>$cell.value</td>"
}
sqlTable<<"</tr>"
}
return sqlTable

I'm running Jira Data Center v8.5.3 and Scriptrunner v6.7.0 with postgreSQL v9.6 on Windows 2016 server (VM).

Thanks in advance for your time and assistance

1 comment

Comment

Log in or Sign up to comment
Richard Bone September 21, 2020

Problem has been resolved! I determined that the issue was due to the quotes used in the select statement. Specifically, the statement should start and end with either single or double quotes and the where clause has to use different quotes; for example:

("select id,customfieldtypekey,cfname from customfield where cfname like 'ABC%' ")

TAGS
AUG Leaders

Atlassian Community Events