Reputation: 139
I am trying to add an asset using a transaction in which I am trying to relate one of the asset's fields with participant reference. But when I m trying to get name of participant using asset, it is showing me undefined
Participant already exists. I don't want to create a new participant using this transaction only asset.
asset TestAsset identified by id {
o String id
--> TestPart part
}
participant TestPart identified by id {
o String id
o String name
}
transaction AddTestAsset {
o String aId
o String pId
}
Logic.js
function addTestAsset(tx) {
var factory = getFactory();
var NAMESPACE = 'org.acme';
var newAsset = factory.newResource(NAMESPACE, 'TestAsset', tx.aId);
newAsset.part = factory.newRelationship(NAMESPACE, 'TestPart', tx.pId);
console.log(newAsset.part.name); //Showing undefined
return getAssetRegistry(NAMESPACE + '.TestAsset')
.then(function (aReg) {
return aReg.add(newAsset);
});
I am getting aId
and pId
from the UI form.
Is there any other way to do it?
Upvotes: 0
Views: 153
Reputation: 5570
This question was also asked and answered on the Rocket.Chat channel
https://chat.hyperledger.org/channel/composer
But here is the summary:
With your console.log(newAsset.part.name);
statement the name
element is undefined as the participant relationship has not been resolved. if you use console.log(newAsset.part);
you will see that it is a Relationship Object, not a Participant.
The relationship can be created for a Participant that does not exist. The design here is that you may not have access to 'see' the Participant through ACL restrictions, so you are allowed to create the relationship.
You could write code to check the presence of the Participant with getParticipantRegistry
Upvotes: 1