Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner External Resources. Retrieve, update database

Hello All,

are the tasks below possible in Scriptrunner? Unfortunately, the documentation is very poor it comes to adding to the external database. I am asking for help, unfortunately I am new to Scriptrunner:

  1.  Read/ write SQL in an external database (or Read/ write CSV or Excel)
  2. Conditionnal display of a field
  3. Fill in custom field from external database
  4. Email notifications

...

Thank you in advance for your help and advices

--

Kazimierz

2 answers

0 votes

The DatabaseUtil is only a shortcut to obtaining a groovy.sql.Sql object.

So it's not really their job to document that class.

You'll find that documentation in pages such as: https://groovy-lang.org/databases.html and https://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html

But short pointers:

  • To read data, you will probably want to use sql.rows() 
  • To update data, you will use sql.execute()
  • This won't help you with Excel or CSV, for that, you will need to find other methods capable of parsing such files. It is not in scope of scriptunner. But I've had some luck myself using com.opencsv.CSVReader for CSV (never tried to work with excel)
  • Conditionally display a field. Not sure what you want here or how that related to scriprunner resources. To hide fields, you'll generally want to use scriptrunner behaviours.
  • Email notifications are also not relevant in the context of db resources. Notifications are usually the result of workflow postfunctions, scripted listener or scripted jobs.

Thank you very much for your answer. I would like to clarify the statement "write SQL in an external database" is it possible to fill in a blank database? e.g. with 

db.executeInsert("INSERT INTO TABLE MyTable VALUES (?, ?, ?)", ['some', 123, myVar])

?

Sure it would look like this:

def keys = DatabaseUtil.withSql('your_scriptrunner_resource_name'){sql->
sql.executeInsert('INSERT INTO TABLE MyTable VALUES (?, ?, ?)', ['some', 123, myVar])
}

log.info "${keys.size()} row(s) were inserted. List of keys: $keys"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New Cloud Apps Roundup - April 2021

Atlassian's marketplace partners have had a very productive start to 2021! Since our last roundup, our developer community has added over 160 new cloud apps to the Atlassian Marketplace to help you...

317 views 3 20
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you