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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Search by attachment name from JQL

Hi.

I created a custom field that uses a scriptrunner to display the attachment name. I would like to search for issues with only attachments, but JQL shows incorrect search results. Can you help me figure out which code is wrong?

 

import com.atlassian.jira.component.ComponentAccessor

def attachments = ComponentAccessor.getAttachmentManager().getAttachments(issue)
def Result = null

Result = attachments.collect {
it.filename

}.join(", ")

return Result

1 answer

1 accepted

0 votes
Answer accepted
Leonard Chew Community Leader Dec 12, 2019

I have created a scripted field called "AttachmentName" with your script, and it seems to be OK.

In which way does your system not work correctly? - Have you run a full reindex?

AttachmentName.png

Ah, I have found the flaw.

Your script always sets a value, even if the attachments are empty, so when you query with "AttachmentName is empty", it will not return any records.

Change your code like this:

import com.atlassian.jira.component.ComponentAccessor

def attachments = ComponentAccessor.getAttachmentManager().getAttachments(issue)
def Result = null

if (!attachments.empty)
{
Result = attachments.collect {
it.filename
}.join(", ")
}

return Result

 

-> leave your result null, if there are no attachments, then you can also query on "is empty"

AttachmentNameEmpty.png

Like # people like this
Leonard Chew Community Leader Dec 12, 2019

Apart from your own scripted field, Scriptrunner provides functions to query for attachments, such as

issueFunction in hasAttachments ("docx")

Maybe you dont even need a scripted field

Thank you for your helpful.

@Leonard Chew : Thanks from another beneficiary!

Suggest an answer

Log in or Sign up to answer
TAGS

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