Copying Attachments from Transition Screen to Sub-Task using the Post Function 'Sequence of Post Functions'

This article provides a code snippet to copy attachment(s) from a transition screen to a newly created sub-task using the post function Sequence of post functions.

 Instructions

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

  2. Select the desired transition.

  3. Click the Post functions tab. Click Add Post function.

  4. From the list, select the post function.

Create a Sub-task

Within the Sequence of post functions post function, add a Create issue(s) post function with the following configuration:

  • Issue Type: Sub-task

  • Summary: [Specify the summary for the sub-task]

  • Configure the remaining options as needed

Set issue fields on new sub-task

Next, add the Set issue fields post function and configure it following the steps below, or as shown in the screenshot below:

Setting the Target Issue:

Insert the following Nunjucks code in the Target issue section:

{{ context.newIssueKey }}

Handling Attachments:

In the Attachment field, select the value Treat value as JSON.

Insert the following Nunjucks code to filter recent attachments (within the last 30 seconds):

{% set recentAttachments = [] %} {% for att in issue.fields.attachment %} {% if now | date("diff", att.created, "seconds") <= 30 %} {% set ignored = recentAttachments.push(att) %} {% endif %} {% endfor %} {{recentAttachments | dump(2)}}

Set any other options based on your specific use case.

This process enables the seamless transfer of attachments from the transition screen to the newly created sub-task.

Â