# Is there a way to duplicate/assign files when creating an entity in an automation?

**URL:** <https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831>\
**Category:** Get Help\
**Tags:** files\
**Created:** [July 22, 2023, 11:44am UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831 "2023-07-22T11:44:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![njyo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/njyo/32/923_2.png) [@njyo](https://community.fibery.io/u/njyo)\
**Post date:** [July 22, 2023, 11:44am UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831/1 "2023-07-22T11:44:17Z")

</div>

So I have an email integration and automation that allows people to reach out and register via email. If they send an email to a given address, I want to automatically create an additional entity and attach any attachments to that newly created entity (not the email):

 ![2023-07-22 at 17.09](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/6/65bfa3562a47f1b8353931961709d536e2a2190e.png)

Somehow in the `Add Field` section, Files does not appear. Is there any way to do this?  
Not a massive thing as we hope to move to a registration form eventually. I assume there’s a cost/benefit trade-off reason in here, just wondering. 🙂

Thanks.

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [July 23, 2023, 8:45pm UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831/2 "2023-07-23T20:45:34Z")

</div>

Could a Rule like the following work on your Email Integration DB?

Trigger: When new Email Message is created, and it has File Attachments

Action: small script to copy the attachments to a target entity:

```auto
const fiberyAccountHostName = 'https://YOURACCOUNT.fibery.io'
const API_TOKEN = '...' // See Workspace menu | Settings | Personal | API Keys

// Where we want to copy the file attachments:
const targetEntityType = '???'
const targetEntityId = ???

for( const entity of args.currentEntities ) {
    for( const file of entity.files ) {
        const file = await fibery.getEntityById('fibery/file', file.id, ['Secret', 'Name',]) // 'Content Type'
        const fileUrl = fiberyAccountHostName + '/api/files/' + file.Secret
        await fibery.addFileFromUrl(fileUrl, file.Name, targetEntityType, targetEntityId, {Authorization: 'Token '+API_TOKEN})
    }
}

```

---

<div class="post-metadata">

**Author:** ![njyo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/njyo/32/923_2.png) [@njyo](https://community.fibery.io/u/njyo)\
**Post date:** [August 3, 2023, 4:24am UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831/3 "2023-08-03T04:24:06Z")

</div>

Thanks a lot, @Matt_Blais, needed a few days to get back to this topic. 🫠

I’ve set this up as a CRON-style job (there is another action that connects the mail with the contact, if that exists already):

 ![2023-08-03 at 12.09](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/c/cade49191246c38b3fde1578781d35f458ad4a67.png)

The main remaining question for me to use this is, how do I pass the `targetEntityId` into the script? I think it should exist in `[Step 1 Email Message].[Contact].[Public Id]` but I’m not sure how to pass it into the script.  
(as [mentioned elsewhere](https://community.fibery.io/t/can-i-use-js-when-creating-a-slack-message/4655/8), the whole scripting interface is unclear to me as the documentation is confusing to me)

Thanks a lot,  
Wolf

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [August 3, 2023, 8:43am UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831/4 "2023-08-03T08:43:56Z")

</div>

> [@njyo](#):
>
> The main remaining question for me to use this is, how do I pass the `targetEntityId` into the script?

The results of previous steps are available in scripts as `args.steps` which is an array.  
So you can examine `args.steps[2]` to get info about the outcome of step 2.

In your case, to get the id, you probably need something like this:  
`args.steps[2].result.entities[0].id`

Admittedly, this capability is not documented very well (at all) so we need to update our user guide, but I’m working on it 🙂

---

<div class="post-metadata">

**Author:** ![njyo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/njyo/32/923_2.png) [@njyo](https://community.fibery.io/u/njyo)\
**Post date:** [August 11, 2023, 2:11pm UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831/5 "2023-08-11T14:11:07Z")

</div>

Thanks, @Matt_Blais and @Chr1sG, with some twiddling this finally worked. 🙂

Mille grazie! 😃

---

<div class="post-metadata">

**Author:** ![mdubakov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/mdubakov/32/10_2.png) [@mdubakov](https://community.fibery.io/u/mdubakov)\
**Post date:** [October 30, 2025, 2:26pm UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831/6 "2025-10-30T14:26:20Z")

</div>

Now you can do it without script

> [@October 30, 2025 / Share entities to web using access templates, New names for access levels, Improved File Fields support in automations](https://community.fibery.io/t/october-30-2025-share-entities-to-web-using-access-templates-new-names-for-access-levels-improved-file-fields-support-in-automations/9924):
>
> Share entities to web using access templates Introducing a new mechanism for sharing entities to web via public links with two major benefits: Everyone can see that an entity is being shared publicly → no accidental overshares. The sharer can control what related entities are shared alongside the main one → no accidental overshares. Now you can, for example, safely share a Projects and its Tasks (but not Allocations) using a public link. Check out the [guide for the new mechanism](https://the.fibery.io/@public/User_Guide/Guide/Share-Entity-to-Web-via-Public-Link-439). T…

---

<div class="post-metadata">

**Author:** ![njyo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/njyo/32/923_2.png) [@njyo](https://community.fibery.io/u/njyo)\
**Post date:** [October 30, 2025, 2:46pm UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831/7 "2025-10-30T14:46:27Z")

</div>

That is an awesome improvement, thanks a lot @mdubakov and team!

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [October 30, 2025, 4:11pm UTC](https://community.fibery.io/t/is-there-a-way-to-duplicate-assign-files-when-creating-an-entity-in-an-automation/4831/8 "2025-10-30T16:11:10Z")

</div>


