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

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