Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to created scripted custom field using script runner

Rajesh Ramankutty
Contributor
April 18, 2022

Dear Team,

I need to create a scripted custom field in which if i add an .docx file it should preview the content in the .docx file.

 

i have a script for .txt file but while m changing according to the .docx files its not working 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.FileSystemAttachmentDirectoryAccessor

 

 

def AttachmentDirecrotryAccessor= ComponentAccessor.getComponent(FileSystemAttachmentDirectoryAccessor)
def output=""

 

 

issue.attachments.each {
log.warn "Our File Name : ${it.filename}"

 

if(it.mimetype == "text/plain" || it.filename.endsWith(".txt"))
{
def directory = AttachmentDirecrotryAccessor.getAttachmentDirectory(issue)
def file = new File(directory, it.id.toString())
def firstLine = file.withReader { it.readLine()}
output += "$it.filename : <br>$firstLine<br><br>"
}
}
log.info "==========================="
log.info output
log.info "============================"
output

1 answer

1 accepted

1 vote
Answer accepted
Anzar
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.
April 18, 2022

Hi Rajesh,

Docx files in groovy/java can be read only through Apache POI which is not included as a library in script runner.

Hence reading a docx file wont be possible.

Regards,

Anzar

Suggest an answer

Log in or Sign up to answer