Creating child tasks while copying files based on certain naming
Asked by Alexandra Peia:

Hello!

I would like to create an automation rule so as, when moving a task to "in progress", to create child tasks.

The trick is that I want to add a number of files to the parent task and I would like for each of the child tasks to automatically copy one of the attachments in the parent. Ideally, I would like for the **child task names** to also inherit the file name of the file it inherits from the parent. Hope this makes sense.

Also, can the number of child tasks be the same as the number of attachments but I can also stick to a predefined number if this is not possible.

Can this be done? Thank you so much!


Answers:
author: Tessa Tuteleers
body: Hi [@Alexandra Peia](/t5/user/viewprofilepage/user-id/5548945) ,

Welcome to the community!

If I understand correct you would like to do the following:

* When you transition a parent issue with attachments
  * Create a subtask for each attachment:
    * Summary = name of the attachment
    * Attachment itself is copied to the subtask

Is this correct?

This can certainly be done, but with some workarounds:

1. You can branch over the different attachments using the **{{attachment}}** smart value.   
   This wil return the attachment or a list of attachements if there are more.
2. In you branch you can create an issue and target the attachment name using **{{file.fileName}}** and the download url uisng**{{file.content}}.**

You would use the URL of the attachment to refer to it in the subtask, as sadly it is not possible to copy a specific attachment to the new issue. (You could copy the attachments themselves, but in that case you always copy ALL attachments).

Doc of attachment smart value [here](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#:~:text=this%20smart%20value.-,%7B%7Battachment%7D%7D,-Accesses%20information%20related).  
You can find a similar question [here](https://community.atlassian.com/t5/Jira-questions/Iterate-through-all-attachments-of-issue-Jira-Cloud-Automation/qaq-p/2104616).

It would look something like this:   
![Screenshot 2024-07-22 114020.png](https://community.atlassian.com/t5/image/serverpage/image-id/336966i4D1266B5B44AF859/image-size/large?v=v2&px=999 "Screenshot 2024-07-22 114020.png")![Screenshot 2024-07-22 114027.png](https://community.atlassian.com/t5/image/serverpage/image-id/336967i15881DA0337E3056/image-size/large?v=v2&px=999 "Screenshot 2024-07-22 114027.png")

Please let me know if you have furter questions!

- Tessa

comments: author: Alexandra Peia
body: Thank you so much, it works great!

One more detail: can I remove part pf the file name? Let's say all my file names will be something likeL "\[B\]Cats and dogs.docx" and I would like the task name to only have "Cats and dogs"? Also, can I add anything to the name, a specific word? It's not mandatory but it would help a lot!


author: Dommalapati Chandrababu Naidu
body: Hi [@Alexandra Peia](/t5/user/viewprofilepage/user-id/5548945)

You can provide filename as you desired in the summary of create issue action.

![Capture.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/337507iBDDA742FC05D565C/image-size/large?v=v2&px=999 "Capture.PNG")

i am not sure about the splitting the file name.

Hope this helps!.

Chandrababu


author: Tessa Tuteleers
body: Hi [@Alexandra Peia](/t5/user/viewprofilepage/user-id/5548945) ,

it is possible to manipulate text, you can find information about it [here](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/).

you would need to get all text before the last "." and it would look something like this then:

```
{{file.fileName.substringBeforeLast(".")}}?
```

There are a lot of fun ways to play around with smaert values, and there is a lot of documentation and examples available, I invite you to look and play around with it if you have to do these sort of manipulations more often :)

You can also drop \[B\] this way is you want and stuff like that. Adding a fixed word to the summary is just by adding the plain text before or after the smart value ;)

Have a great day and if this helped you, please accept my original answer so people can find the solution quicker.

- Tessa


author: Alexandra Peia
body: Thank you so much!


author: Dommalapati Chandrababu Naidu
body: Hi Alexandra,

Welcome to Atlassian community.

Kindly follow below link. Mr. Esteban has mentioned the flow in his answer.

<https://community.atlassian.com/t5/Jira-Service-Management/Re-Jira-Automation-Create-Subtasks-for-each-attachment/qaq-p/2455777/comment-id/145416#M145416>


Tags: cloud

jira-cloud