Mohamed Assem
Mohamed Assem

Reputation: 164

Hyperledger query never return results

I`m trying to query my business network using buildQuery but it always returns an empty array.
My code is as follows.

This is the connection.js file:

module.exports = {
BusinessNetworkConnection : require('composer-client').BusinessNetworkConnection,
cardName : '',
connection: {},

connect : function() {

    var cardType = { type: 'composer-wallet-filesystem' }
    this.connection = new this.BusinessNetworkConnection(cardType);

    return this.connection.connect(this.cardName);
},

disconnect : function(callback) {
    this.connection.disconnect();
}
};

This is my query.js file which being invoked to get results:

const connection = require('./connection');

const getContacts = async (cardName,companyID) => {
connection.cardName = cardName;
try {
    await connection.connect(); 
    main();
} catch (error) {
    main(error);
}

async function main(error) {
    if (error) { return new Error("Ops Error: ",error) };

    const statement = 'SELECT org.finance.einvoice.participant.Company WHERE (participantId == _$companyID)'
    const query = await connection.connection.buildQuery(statement);
    const company = await connection.connection.query(query, { companyID }).catch(err => {return new Error(err)});
    await connection.connection.disconnect().catch(err => new Error(err));
    console.log(company);
    return company;
};
};


module.exports = {
   getContacts
};

The expected behavior from getContacts() is to return an asset from business network but it actually returns an empty array.
Current versions: composer-cli 0.20 , composer-playground 0.20 , composer-client 0.20 , composer-common 0.20 and fabric-dev-server 1.2 .

Upvotes: 0

Views: 132

Answers (1)

Mohamed Assem
Mohamed Assem

Reputation: 164

i found the solution for this issue. i was using card which was not allowed to perform queries. However, when i used the admin card it returned with results. other way is to allow participants to issue queries in permission.acl file.

Upvotes: 1

Related Questions