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
• 26,740 points
1,447 views

1 answer to this question.

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
• 69,210 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,350 points
1,201 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
• 26,740 points
637 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,237 views
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
• 26,740 points
732 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
• 69,210 points
643 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP