Forums

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

How to implement an attachment picker?

Sascha Ziemann
Contributor
July 20, 2022

I want a user selecting an existing issue attachment during a transition in order to do something with the selected attachment in the post function.

How to get an attachment picker?

1 answer

0 votes
Sascha Ziemann
Contributor
July 21, 2022

I think I got it myself. I am using the custom picker of Scriptrunner.

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption

search = { String inputValue, Issue issue ->
    issue.getAttachments().findAll { it.getFilename().contains (inputValue ?: '') }
}

toOption = { Attachment attachment, Closure<String> highlight ->
    new PickerOption(
        value: attachment.getId(),
        label: attachment.getFilename(),
        html: highlight(attachment.getFilename(), false),
    )
}

getItemFromId = { String id ->
    ComponentAccessor.getAttachmentManager().getAttachment(id as Long)
}

renderItemViewHtml = { Attachment attachment ->
    attachment.getFilename()
}

renderItemTextOnlyValue = { Attachment attachment ->
    attachment.getFilename()
}

 

Suggest an answer

Log in or Sign up to answer