Script equivalent of the "Convert to" feature?

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:

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, {
		// ...
    });
}
1 Like

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.

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);
}
7 Likes

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

This just helped me too! Thanks @Dimitri_S !

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!