Hyperledger Composer: How to retrieve array of assets?

0 votes

The model I have defined is as follows:

asset Ask identified by askId
{
    o String askId
    o String title
    o String[] options
    o Integer[] votes
}


asset Poll identified by pollId
{
    o String pollId
    --> Ask[] asks
}

when I try to get the asks field I am not able to get anything. Here is the test code:

count.poll.asks.forEach(function(ask)
{
       alert("Ask:" +ask);
});

How can i retrieve array of assets?

Nov 14, 2018 in Blockchain by digger
• 27,620 points
245 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

This is what worked for me:

asset Ask identified by askId
{
    o String askId
    o String title
    o String[] options
    o Integer[] votes
}


asset Poll identified by pollId
{  
    o String pollId
    --> Ask[] asks
}

transaction count {
    --> Poll pollId
}

transaction processor function :

/**
 * count transaction
 * @param {org.sample.count} count
 * @transaction
 */
function count(count) {
  count.pollId.asks.forEach(function(ask) {
    var serializer = getSerializer()
    var serializer = getSerializer();
    var jsonObj = serializer.toJSON(ask);
    console.log("Ask: ", ask);
    console.log("Ask jsonObj: ", jsonObj);    
  });
}

try this and see if this works

answered Nov 14, 2018 by Omkar
• 67,000 points

Related Questions In Blockchain

0 votes
1 answer

How to retrieve complete world state of hyperledger?

you can achieve this by iteration process ...READ MORE

answered Jul 5, 2018 in Blockchain by slayer
• 29,040 points
178 views
0 votes
1 answer

How to control visibility of assets in Hyperledger Fabric?

you can use proof of Authority consensus ...READ MORE

answered Jul 10, 2018 in Blockchain by digger
• 27,620 points
74 views
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 27,620 points
52 views
+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer

Hyperledger: How to retrieve properties of relationship through query?

I dont think its possible using query. ...READ MORE

answered Nov 8, 2018 in Blockchain by Omkar
• 67,000 points
52 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.