# Script equivalent of the "Convert to" feature?

**URL:** <https://community.fibery.io/t/script-equivalent-of-the-convert-to-feature/2296>\
**Category:** API & Programming\
**Created:** [December 8, 2021, 12:36am UTC](https://community.fibery.io/t/script-equivalent-of-the-convert-to-feature/2296 "2021-12-08T00:36:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimitri\_S](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/dimitri_s/32/1683_2.png) [@Dimitri\_S](https://community.fibery.io/u/Dimitri_S)\
**Post date:** [December 8, 2021, 12:36am UTC](https://community.fibery.io/t/script-equivalent-of-the-convert-to-feature/2296/1 "2021-12-08T00:36:10Z")

</div>

I have an entity in one Space I want to move to another, would use the Convert to feature but some of the field names may not match.

In its simplest form I want to copy a few simple fields (Name and Salary) from an entity from **Space A \> Db X** to **Space B \> Db Y**.

The part I’m not sure about is how to specify `fibery.createEntity` to do so in **Space B \> Db Y**.

Here is what I have so far:

```auto
const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {
    const name = entity['Name'];
    const salary = entity['Salary'];

    await fibery.createEntity(entity.type, entity.id, {
		// ...
    });
}

```

---

<div class="post-metadata">

**Author:** ![Dimitri\_S](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/dimitri_s/32/1683_2.png) [@Dimitri\_S](https://community.fibery.io/u/Dimitri_S)\
**Post date:** [December 8, 2021, 12:49am UTC](https://community.fibery.io/t/script-equivalent-of-the-convert-to-feature/2296/2 "2021-12-08T00:49:58Z")

</div>

Figured it out but leaving this up here for others reference.

Here is my script equivalent of the Convert to feature but with the ability to map to dissimilarly named fields.

```auto
const fibery = context.getService("fibery");

for (const entity of args.currentEntities) {
	await fibery.createEntity("Space B/Db Y", {
		"Person Name": entity["Name"],
		"Person Salary": entity["Salary"],
	});
    await fibery.deleteEntity(entity.type, entity.id);
}

```

---

<div class="post-metadata">

**Author:** ![cover](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/cover/32/11891_2.png) [@cover](https://community.fibery.io/u/cover)\
**Post date:** [February 9, 2022, 8:56pm UTC](https://community.fibery.io/t/script-equivalent-of-the-convert-to-feature/2296/3 "2022-02-09T20:56:26Z")

</div>

OMG many thanks! Just faced such a goal to achieve and here is handy solution, tx!!! 🙂

---

<div class="post-metadata">

**Author:** ![Tommy\_Hedley](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/tommy_hedley/32/6468_2.png) [@Tommy\_Hedley](https://community.fibery.io/u/Tommy_Hedley)\
**Post date:** [March 4, 2023, 9:00pm UTC](https://community.fibery.io/t/script-equivalent-of-the-convert-to-feature/2296/4 "2023-03-04T21:00:53Z")

</div>

This just helped me too! Thanks @Dimitri_S !

---

<div class="post-metadata">

**Author:** ![Joe\_H](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/joe_h/32/6575_2.png) [@Joe\_H](https://community.fibery.io/u/Joe_H)\
**Post date:** [May 2, 2023, 9:03pm UTC](https://community.fibery.io/t/script-equivalent-of-the-convert-to-feature/2296/5 "2023-05-02T21:03:53Z")

</div>

Hey Dimitri,  
Any idea how would I do this if I just want to use the convert feature to move from one database to another & the field names are the same via automation script?

I can get it to create the new entity, but I’m duplicating email messages (with attachments & rich text message fields) & am getting errors on the message ID and Files.

Thanks!
