Access and read from .csv file in Script Runner

Ivana Srebrenova October 17, 2022

Hello everyone

Is it possible to access from any location the .csv file and read it with Script Runner on Cloud?

1 answer

Suggest an answer

Log in or Sign up to answer
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.
October 17, 2022

Yes, you can write code for SR that can reach out to other accessible sites and read data from them.

How are you publishing your CSV?  Is it available on a proper URL, or are you looking at non-canonical UNCs like file shares?

Ivana Srebrenova October 17, 2022

 

Thank you @Nic Brough -Adaptavist-  for the reply, 

I am not limited of the location of the file, I just want to successfully accessing it. 

First I thought to be attached on an issue (attachment), but I couldn't find how to access from there on Cloud, so I put the file on Google Sheets, and tried this code:

 

import com.opencsv.CSVReader;

@GRAPES(
@grab(group='com.opencsv', module='opencsv', version='5.7.0')
)

def filePath = 'urlFromGoogleSheetsFile'
def reader = new CSVReader(new FileReader(new File(filePath)))
def data= reader.collect { it }.with { rows ->
def header = rows.head()
def dataRows = rows.tail()

dataRows.collect { row ->
[header, row].transpose().collectEntries()
}
}

data.each{row->
// access any data from the row by the name of the header
// for example, row['colHeader'] or row.colHeader
}

..........

But I got this type of exception:

Screenshot_61.png

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.
October 19, 2022

Ah, ok, reading the file, not a problem with getting it.

SR for Cloud doesn't import extra libraries like that - you'd need to get us (Adaptavist) to add it to the server running your scripts.

Have a look at https://library.adaptavist.com/entity/bulk-update-the-value-of-a-custom-field-on-jira-issues - that tells you how to read a remote file, but you're going to have to write code to parse it.

Ivana Srebrenova October 19, 2022

I checked the link, but it shows me how to update the value of a Custom Field on Jira Issue.

Also the idea is to reach some csv file through SR on Cloud, no matter on which location is, so it can read what is inside the file and do some stuff inside Jira?

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.
October 19, 2022

Yes, sorry, it was only supposed to be showing you another way to read a file, but I didn't say that.

You will need to code something that can parse the files you are reading.

Ivana Srebrenova October 19, 2022

Okey. the code for parsing a file is not a problem, Firstly is there some documentation/example how to reach the file from SR ?

Ojase Emmanuval
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 11, 2023

@Ivana Srebrenova Have you had any luck with reading the CSV file and get this implemented. We have a similar requirement. Any help would be much appreciated.

Thanks,

Ojase

Ivana Srebrenova May 12, 2023

Hello @Ojase Emmanuval since this implementation was intended for cloud this solution with accessing and reading a CSV file on Jira cloud with Script Runner was not possible, because of limitation on which libraries and packages can be imported there and also unfortunately Atlassian does not provide access to the file system. On server it is possible.

As a workaround we use the Import/Export option: https://support.atlassian.com/jira-cloud-administration/docs/import-data-from-a-csv-file/  and worked with automation.

I think this will be helpful for you too.

Ojase Emmanuval
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 14, 2023

@Ivana Srebrenova Thanks for the reply. What you mean by "worked with automation". Were u able to make use of JIRA automations to do anything similar?

 

Thanks,

Ojase 

TAGS
AUG Leaders

Atlassian Community Events