I am trying to use for-loop in the transaction. The for-loop basically creates new assets, ie. I am creating a new asset on each iteration.
The problem is that each time the loop iterates the value of vals.length remains zero(0). And if I try to do console.log(vals) then to it shows null array even when loop iterates for i=1,2,3...
But once whole transaction function gets completed then I am able to see the assets in UI.
model.cto
asset Net identified by NetNumber{
o String NetNumber
o Integer totaltransaction
}
transaction GenerateNet {
}
logic.js
/**
* submit an order
* @param {org.demo.invoice.GenerateNet}
* @transaction
*/
async function GenerateNet(){
var amt = [200, 500, 700];
var netNumber = ['aa', 'bb', 'cc'];
for(var i=0; i < amt.length; i++){
let netRegistry = await getAssetRegistry('org.demo.invoice.Net');
let vals = await netRegistry.getAll();
console.log(vals.length);
console.log(vals);
let newNetting = factory.newResource('org.demo.invoice','Net', netNumber);
newNetting.totaltransaction = amt[i];
await nettingRegistry.add(newNetting);
}
}
I want to see the value of vals.length to be 1,2,3 as the iteration goes on.