To create a new asset in Fabric composer in the transaction, you have to do the following steps:
0. Supposing you have a model file and an asset:
asset AssetName identified by <primkey> {
o <type> <primkey>
o <type> RequiredField1
o <type> RequiredField2
...
}1. get a factory object: it helps you to create other resources, events, assets and so on.
const factory = getFactory();
2. create a new asset with the help of the factory newResource call and with a new value for the primary key. After that update all the required fields for your asset.
const newAsset=factory.newResource(namespace,'AssetName', <primkey>);
newAsset.RequiredField1 = value1;
newAsset.RequiredField2 = value2;
...
3. Get an asset registry to update your asset:
const newAssetRegistry = await getAssetRegistry(namespace + '.AssetName');
4. add the new asset to the asset registry.
await newAssetRegistry.add(newAsset);