Hello,
I wanted to transfer all the data including the linked object value from Object A to Object B using code repository, however, my attempt did not work. Its not getting the actual properties of the object.
this is the typescript code:
import { Function, OntologyEditFunction, Edits } from "@foundry/functions-api";
import { Objects, Product } from "@foundry/ontology-api";
class PropertyManager {
private properties: { [key: string]: any };
constructor(initialProperties: { [key: string]: any } = {}) {
this.properties = { ...initialProperties };
}
// Method to get all properties
public getProperties(): { [key: string]: any } {
return this.properties;
}
// Method to set a property
public setProperty(key: string, value: any): void {
this.properties[key] = value;
}
}
function propertiesSetter(source:any, target:any)
{
const sourceProdProperties = new PropertyManager(source);
const targetProdProperties = new PropertyManager(target);
console.log(sourceProdProperties);
console.log(targetProdProperties);
for (const key in sourceProdProperties.getProperties()) {
if (sourceProdProperties.getProperties().hasOwnProperty(key)) {
targetProdProperties.setProperty(key, sourceProdProperties.getProperties()[key]);
}
}
}
export class MyFunctions {
@Edits(Product)
@OntologyEditFunction()
public async transferProduct(sourceProduct: Product): Promise<void> {
//Product Information
let prod = Objects.create().ExtProduct(sourceProduct.mediaItemRid);
propertiesSetter(sourceProduct,prod);
}
}
console (which I have zero understanding):
LOG [2025-03-13T07:30:33.866Z] { properties:
{ osp:
{ delegate: [Object],
virtualToConcreteRemapper: {},
type: 'REMAPPED_STORE' },
primaryKeySupplier: '() => primaryKey',
rid: 'ri.phonograph2-objects.main.object.bae0b0d8-6e19-4c4f-9d83-146214bed3',
typeId: 'c6bxdntz.product',
primaryKey: '[Circular]' } }
LOG [2025-03-13T07:30:33.867Z] { properties:
{ osp:
{ delegate: [Object],
virtualToConcreteRemapper: {},
type: 'REMAPPED_STORE' },
primaryKeySupplier: '() => primaryKey',
typeId: 'c6bxdntz.ext-product',
primaryKey: '[Circular]' } }