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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,470
Community Members
 
Community Events
184
Community Groups

Gettin null output in scriptrunner

Hello folks,

 I have been trying to read a CSV via Groovy and spit out the values of columns into defined variables.

I used CsvReader to read the header and the records. When I run this code in my local groovy console, it gives me the desired output. But when I run it in JIRA Scriptrunner, it give me a null output. Not sure what I'm doing wrong.

Need some help please.

 

import java.io.FileNotFoundException
import java.io.IOException
import com.csvreader.CsvReader

CsvReader products = new CsvReader("D:/Program Files/Atlassian/JIRA/files/test.csv")

    products.readHeaders()

    while (products.readRecord())
    {
    String id = products.get("ID")
    String project = products.get("Project")
    String time_entry = products.get("Open_for_Time_Entry")
    String clarity = products.get("Clarity_Project")
    String action = products.get("Action")
    String length = products.get("Length")
    String type = products.get("Type")
    String summary = products.get("Summary")

    System.out.println(id + "\t" + project + "\t" + time_entry + "\t" + clarity)
 }
    products.close()

2 comments

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 04, 2019

Have you tried running it in the ScriptRunner console and check the logs it gathers as it runs?

My best guess is that it's either going to show an error opening the file, or the null is what you'd expect as the script has no output to go to the screen.  (System.out.println is dropped into the logs, not the screen)

Ben Poulson
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.
Jun 04, 2019

Ugh, I've run into this. The problem is that the groovy console doesn't support println. There are two ways to do it.

 

1) log output rather than printing it (just need to replace system.out.println with log.error)

2) Returning whatever it is you want to display (can't put it in a loop though, since a return outside a function will exit the script)

 

Bonus tip, Groovy doesn't require a variable to be declared as a type (it's like javascript in that aspect). Instead of declaring your variables as type String, you could declare them as type def. String works too, def is just also an option.

 

Let me know if that fixed it!

Like Raman Kumar likes this

Thanks a lot Ben!

It worked.

Like Ben Poulson likes this
Ben Poulson
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.
Jun 05, 2019

No problem! If that fixed it, could you go ahead and mark my response as the answer?

 

Thanks!

somehow unable to mark the answer

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 06, 2019

It's because you created a "discussion" instead of a "question".

Hi,

For Instance,

if def a and def b, i want to  return both the values, it returns only a.

def a = "hello"
return a
def b = "hey"
return b

 

output:

hello

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 17, 2020

The "return" directive ends processing of the script as it feeds back a result.

Like # people like this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events