Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This article provides the code snippet to delete attachment(s) that have a specific word in the file name using Build-your-own (scripted) Post-function

\uD83D\uDCD8 Instructions

  1. Navigate to the intended workflow to make the necessary changes in the edit mode.

  2. Select the required transition.

  3. Select the Post functions tab and click Add post function.

  4. Add the Build-your-own (scripted) Post-function

  5. Add the below Nunjucks script:

    Code Block
    languagejava
    {% for att in issue.fields.attachment %}
    {% if (att | field("filename")).includes("test") %}
    {{ "/rest/api/2/attachment/:id" | callJira(verb="DELETE",params={"id":att | field("id")}) }}
    {% endif %}
    {% endfor %}

The above template deletes the attachment(s) that contain the word test in the filename (modify test in line #2 with your desired text)

Image RemovedImage Added
Info

If this post-function is added on the create transition, select the checkbox “Delay the execution of this post-function” under “Delayed execution” and select a delay of 3 seconds.

References

Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@4371b12
sortmodified
showSpacefalse
reversetrue
typepage
cqllabel in ( "kb-how-to-article" , "nunjucks-template" , "attachment" , "delete" , "post-function" ) and type = "page" and space = "JMWEC"
labelskb-how-to-article