# \[✔️ DONE\] Duplicate a record

**URL:** <https://community.fibery.io/t/done-duplicate-a-record/386>\
**Category:** Ideas & Features\
**Created:** [October 28, 2019, 2:13am UTC](https://community.fibery.io/t/done-duplicate-a-record/386 "2019-10-28T02:13:19Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickcogley](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/rickcogley/32/274_2.png) [@rickcogley](https://community.fibery.io/u/rickcogley)\
**Post date:** [October 28, 2019, 2:13am UTC](https://community.fibery.io/t/done-duplicate-a-record/386/1 "2019-10-28T02:13:19Z")

</div>

Hi - it would be useful if there were a way to easily duplicate a record.

One use case is, if you make a “template” record somewhere, with text you want to re-use frequently, you might want to easily copy-paste that.

Is a button the way to go for this?

---

<div class="post-metadata">

**Author:** ![helloitse](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/helloitse/32/498_2.png) [@helloitse](https://community.fibery.io/u/helloitse)\
**Post date:** [August 29, 2020, 4:39pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/2 "2020-08-29T16:39:12Z")

</div>

Hopefully, since multi-select is a feature, this is not far behind.

---

<div class="post-metadata">

**Author:** ![B\_Sp](https://avatars.discourse-cdn.com/v4/letter/b/e8c25b/32.png) [@B\_Sp](https://community.fibery.io/u/B_Sp)\
**Post date:** [September 14, 2020, 6:37am UTC](https://community.fibery.io/t/done-duplicate-a-record/386/3 "2020-09-14T06:37:55Z")

</div>

Would love to see some templating-type functionality alongside this as well!

---

<div class="post-metadata">

**Author:** ![XLN](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/xln/32/948_2.png) [@XLN](https://community.fibery.io/u/XLN)\
**Post date:** [October 20, 2020, 7:26am UTC](https://community.fibery.io/t/done-duplicate-a-record/386/4 "2020-10-20T07:26:42Z")

</div>

+1 ! We would love to implement “processes made of checklists” in Fibery, to link them to actual tasks & projects, but without the “duplicate” feature this does not really make sense. Any visibility on when this would be implemented ? Thanks !

---

<div class="post-metadata">

**Author:** ![Polina\_Zenevich](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/polina_zenevich/32/480_2.png) [@Polina\_Zenevich](https://community.fibery.io/u/Polina_Zenevich)\
**Post date:** [October 21, 2020, 1:07pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/5 "2020-10-21T13:07:12Z")

</div>

Hi!  
So, do you need to duplicate a record or more smth like a recurring process? Lik Projects with repetitive Tasks and etc.

---

<div class="post-metadata">

**Author:** ![XLN](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/xln/32/948_2.png) [@XLN](https://community.fibery.io/u/XLN)\
**Post date:** [October 21, 2020, 1:30pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/6 "2020-10-21T13:30:01Z")

</div>

Hi, in our case cloning records will be enough, we will put checklists directly into records, with 1 record = 1 process

---

<div class="post-metadata">

**Author:** ![Polina\_Zenevich](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/polina_zenevich/32/480_2.png) [@Polina\_Zenevich](https://community.fibery.io/u/Polina_Zenevich)\
**Post date:** [October 22, 2020, 9:27am UTC](https://community.fibery.io/t/done-duplicate-a-record/386/7 "2020-10-22T09:27:43Z")

</div>

Then I can suggest you add a Duplicate a record button 🙂  
Here is the code you can use

```
const fibery = context.getService('fibery');
const schema = await fibery.getSchema();

await Promise.all(args.currentEntities.map(async (template) => {
    const type = template.type;

    const newEntityTemplate = schema.typeObjectsByName[type].fieldObjects
        .reduce((result, fieldObject) => {
            if (fieldObject.type === "fibery/Button" || fieldObject.type === "Collaboration~Documents/Document" || fieldObject.isReadOnly) {
                return result;
            } else if (fieldObject.typeObject.isPrimitive) {
                return { ...result, [fieldObject.title]: template[fieldObject.title] };
            } else if (fieldObject.typeObject.isEnum && fieldObject.cardinality === ":cardinality/many-to-one") {
                // Workaround for issue with setting null to enums
                const enumSetter = template[fieldObject.title].Name ? { [fieldObject.title]: template[fieldObject.title].Name } : {};
                return { ...result, ...enumSetter };
            } else if (fieldObject.typeObject.isPrimitive === false && fieldObject.cardinality === ":cardinality/many-to-one") {
                return { ...result, [fieldObject.title]: template[fieldObject.title].Id };
            } else {
                return result;
            }
        }, {});

    console.log(newEntityTemplate);
    // create new entity with some name
    // see https://api.fibery.io/#script
    const [{ result: newEntity }] = await fibery.createEntity(
        type,
        {
            ...newEntityTemplate,
            Rank: template.Rank + 10000,
            Name: `${template.Name} Copy`
        });

    // Copy multiselect enums
    const multiSelectEnumFields = schema.typeObjectsByName[type].fieldObjects
        .filter((fieldObject) => fieldObject.typeObject.isEnum && fieldObject.cardinality === ":cardinality/many-to-many" && fieldObject.isReadOnly === false);
    for (const multiSelectEnumField of multiSelectEnumFields) {
        if (template[multiSelectEnumField.title]) {
            await Promise.all(template[multiSelectEnumField.title].map((val) => fibery.addCollectionItem(type, newEntity["fibery/id"], multiSelectEnumField.name, val.Id)));
        }
    }

    // copy assignees
    const assigneesField = schema.typeObjectsByName[type].fieldObjects
        .find((fieldObject) => fieldObject.name === "assignments/assignees");
    if (assigneesField && template[assigneesField.title]) {
        await Promise.all(template[assigneesField.title].map((val) => fibery.addCollectionItem(type, newEntity["fibery/id"], assigneesField.name, val.Id)));
    }

    //At the moment we cannot set rich text fields using 'createEntity' api, so we set it using 'setDocumentContent' method
    const richTextFields = schema.typeObjectsByName[type].fieldObjects.filter(f => f.type === "Collaboration~Documents/Document");
    for (const richTextField of richTextFields) {
        const content = await fibery.getDocumentContent(template[richTextField.title].Secret, "json");
        if (!content) {
            continue;
        }
        // take deep details of newly created entity (mainly interested in description Secret)
        // see https://api.fibery.io/#get-entities
        // NOTE: unfortunately #script api doesn't support such deep query at the moment
        // getEntity(id, ["id", ["Description", "Secret"]]) would make things much simplier
        const newEntityDetails = await fibery.executeSingleCommand(
            {
                "command": "fibery.entity/query",
                "args": {
                    "query": {
                        "q/from": type,
                        "q/select": {
                            "Id": "fibery/id",
                            "RichTextField": {
                                "Id": [richTextField.name, "fibery/id"],
                                "Secret": [richTextField.name, "Collaboration~Documents/secret"]
                            },
                        },
                        "q/where": ["=", ["fibery/id"], "$id"],
                        "q/limit": 1
                    },
                    "params": { "$id": newEntity["fibery/id"] }
                }
            });

        // fail if details object not found
        if (!newEntityDetails) {
            throw new Error(`Request for new entity details is failed`);
        }

        const newSecret = newEntityDetails[0].RichTextField.Secret;
        const result = await fibery.setDocumentContent(newSecret, content, 'json');
    }
}));
```

---

<div class="post-metadata">

**Author:** ![NicolSpies](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/nicolspies/32/4317_2.png) [@NicolSpies](https://community.fibery.io/u/NicolSpies)\
**Post date:** [October 30, 2020, 8:14am UTC](https://community.fibery.io/t/done-duplicate-a-record/386/8 "2020-10-30T08:14:33Z")

</div>

Hi @Polina_Zenevich, I have been diving deep since starting with Fibery a few weeks ago specifically into the action buttons requiring me to start using Javascript.

I have been trying to achieve the following by modify the record duplication example:  
When the script is executed I want to retrieve the information in the Name field (I think the name field acts as the primary key in the table) and generate a new entity in a different template (another type in another app) using the retrieved Name field information as the name newly created entity.

I found the record duplication script a the best fit to start with and are trying to modify it to achieve the above.

I do not know if you are the correct person to ask.

---

<div class="post-metadata">

**Author:** ![antoniokov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/antoniokov/32/201_2.png) [@antoniokov](https://community.fibery.io/u/antoniokov)\
**Post date:** [November 2, 2020, 6:19pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/9 "2020-11-02T18:19:45Z")

</div>

Hi @NicolSpies,

Is Name the only Field you’d like to copy or are there more?  
I’m trying to pick the most relevant example from our library or to write a new one.

Also, it would be great if you share the scenario behind the button: what the Types are and when users trigger the button. This would help us to organize these buttons and code snippets so other creators could find them in the future.

Cheers!

---

<div class="post-metadata">

**Author:** ![NicolSpies](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/nicolspies/32/4317_2.png) [@NicolSpies](https://community.fibery.io/u/NicolSpies)\
**Post date:** [November 2, 2020, 8:46pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/10 "2020-11-02T20:46:40Z")

</div>

Hi Anton,  
The reason why I only ask about the Name field is to automate the following:

1. I create two types in the same or different apps.
2. I create a relationship between the two types and select to automatically linked records between the two types based on the Name fields being equal between the two records.
3. When I now manually add a record to the second type with lookup fields to a record in the first type, the fields will stay blank until I enter the first type record name in the second type record name. Then the automatic linking applies and the look up fields in the second record are populated with data from the first type. This is a manual and long process.
4. If I add a scripted button doing the above, it can add the record to the second type, copy the name of the current record in the first type across so that the automatic linking is activated and the lookup information are updated.
5. It would also be nice to check in the records of the second type if a record with the specific name already exists. If it does, the script exists on order not to create a duplicate named linked record in the second type.
6. I would also add a check box field that it set true when the code is executed to show in the first type if the action button script has been executed for the specific record to generate the linked record in the second type already.
7. From the code I would then be able to see how it is done and modify the script for any other field to be used automatic rule based linking of records.
8. I suppose this process implies the created by and Creation Date fields also needs to be copied with the name field.
9. If I extend this script, I can let the action button script create records in multiple related type tables.

I hope this makes sense.

---

<div class="post-metadata">

**Author:** ![NicolSpies](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/nicolspies/32/4317_2.png) [@NicolSpies](https://community.fibery.io/u/NicolSpies)\
**Post date:** [November 6, 2020, 9:37am UTC](https://community.fibery.io/t/done-duplicate-a-record/386/11 "2020-11-06T09:37:18Z")

</div>

@antoniokov, I assume my explanation was clear 😀

---

<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:** [April 28, 2021, 1:12pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/12 "2021-04-28T13:12:32Z")

</div>

Implemented recently

> [@CHANGELOG: April 14 / Duplicate entity, Audit Log for all users, Convert entity improvements](https://community.fibery.io/t/changelog-april-14-duplicate-entity-audit-log-for-all-users-convert-entity-improvements/1557):
>
> Duplicate entity Now you can duplicate any entity in Fibery. Just find Duplicate action in … menu in Entity View or on a card: [2021-04-14 15.54.40] Note: Entity duplication doesn’t duplicate inner Collections and References. For example, if you have a project with 100 tasks and duplicate this project, a new project with 0 tasks will be created. Audit Log is accessible by all users In previous releases Audit Log was visible for Admins only, now any user has access to the Audit Log. It takes…

---

<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:** [May 13, 2022, 3:58pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/13 "2022-05-13T15:58:49Z")

</div>

@Polina_Zenevich, could you share a Button script to accomplish the following:

- get the content of a Rich Text field
- prepend this content to the first linked Document

---

<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:** [November 8, 2022, 2:30pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/14 "2022-11-08T14:30:16Z")

</div>

4 posts were split to a new topic: [Duplicate many-to-many relations when an entity is duplicated](https://community.fibery.io/t/duplicate-many-to-many-relations-when-an-entity-is-duplicated/3500)

---

<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:** [November 22, 2022, 3:17pm UTC](https://community.fibery.io/t/done-duplicate-a-record/386/15 "2022-11-22T15:17:40Z")

</div>


