Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
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

Where do I drop the CSV file so my ScriptRunner script can see it?

I am writing a script that needs to read some data from a csv file.  This is the line that I want to use to access the file and store the data.

InputStream inputFile = getClass().classLoader.getResourceAsStream("projectToEpicMap.csv")
String[] lines = inputFile.text.split('\n')
List<String[]> rows = lines.collect {
it.split(',')
}

Where do I have to put my csv file so this line will be able to access it?  At the moment all I am receiving is a NullPointerException.  Right now I have the csv file in this location.

<JIRA Install Directory>\atlassian-jira\WEB-INF\lib

1 answer

1 accepted

Hi Mark,

I made a slight change to your script. I have used "File" instead of using the classloader as it's a simpler approach. I also added an if statement to check for the presence of the file, so that you get more useful output than before in case the file is not found.

File file = new File("<path_to_jira_home>/files/test.csv") // <-- Change this to your path...

if (file.exists() && file.isFile()) {
String[] lines = file.text.split('\n')
List<String[]> rows = lines.collect {
it.split(',')
}
} else {
"No file found at that location..."
}

A couple of points on this:

1. Create a new directory in your JIRA_HOME directory for storing these kinds of files.

2. You need to provide an absolute path to the files on the server. I don't believe this will work with relative paths.

You should be able to run this script in your "Script Console" as-is to test. I would always recommend against carrying out this kind of development in your production JIRA instance. It is always best to test these changes in a pre-production instance first :-)

I hope this helps!

Steve

Hi @Stephen Cheesley _Adaptavist_@Mark Finta, can you please provide the complete script to acomplish this. I want to read a csv file from my local system and create/update tickets in Jira

Hey @Hemanshu Sood

Unfortunately, I don't have time right now to write the whole script front to back. The snippet provided in my response should do 75% of what you want. You simply need to add the logic that will update JIRA issues based on the content. It should be straight forward enough. You can use the Atlassian Java API to help you find out how to update JIRA issues.

Feel free to come back if you get stuck or have any specific questions :-)

One small Problem Stephen... She's a not working! What is it we're doing wrong?

image.png

Hey Joel,

Does the script work if you try to run it? Your getting a static type checking error, but the script may still work. If the script fails to run, what is the error message from the script output?

I couldn't get it to run with the same code so instead I just iterated through it with a for. I had to do as such anyways since what I'm doing is importing a series of Project Components via a csv file. 

Your code was a fantastic start and got me on the right path, thanks! ... I ended up with this:


if (file.exists() && file.isFile()) {
String[] lines = file.text.split('\n');
lines.length;
for(int i=0; i<lines.length; i++){

if(created>=MAXCompLimit){
break;
}
def r = lines[i].split(',');
try {
if(compmgr.findByComponentName(targPID, r[0]) == null){
//create
compmgr.create(r[0], r[1].trim(), '', 0, targPID);
created++
}else{
//skip
}
} catch(Exception e1) {
//Catch block
log.error(e1);
}
}
} else {
log.error("No file found at that location ["+FilePath+"]");
}

 

Suggest an answer

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

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

177 views 2 1
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