1

I can add participant through command line command such as below successfully.

composer participant add -c admin@health-network -d '{"$class": "org.acme.health.Patient", "patientId": "10", "firstName": "Mae", "lastName": "smith", "email": "smith@gmail.com"}'

However, when I try javascript API, I get this error.

Error: Error trying to query business network. Error: chaincode error (status: 500, message: Error: Object with ID 'Participant:org.acme.health' in collection with ID '$sysregistries' does not exist) at channel.queryByChaincode.then.catch (/home/sara/health-network/angular-app/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:809:34) at

Here is my javascript code

const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
let businessNetworkConnection = new BusinessNetworkConnection();
return businessNetworkConnection.connect('admin@health-network')
.then(() => {
    return businessNetworkConnection.getParticipantRegistry('org.acme.health');
})

.then((participantRegistry) => {
    let factory = businessNetworkConnection.getFactory();
    let participant = factory.newResource('org.acme.health', 'Patient', '10');
    participant.firstName = 'Mae';
    participant.lastName = 'Smith';
    participant.email ='smith@gmail.com'
    return participantRegistry.add(participant);
})
.then(() => {
    return businessNetworkConnection.disconnect();
})
.catch((error) => {
    console.error(error);
    process.exit(1);

});

I have a participant named 'Patient' in my .cto file.

ethertest
  • 317
  • 4
  • 13

2 Answers2

1

I found the problem I need to define the resource in getParticipantRegistery('org.acme.health.Patient').

ethertest
  • 317
  • 4
  • 13
  • correct - or `return businessNetworkConnection.getParticipantRegistry('org.acme.health.Patient');` even – Paul O'Mahony Feb 27 '18 at 13:10
  • I followed the same but getting a strange error like: "TypeError: businessNetworkConnection.getFactory is not a function". '$sysregistries' does not exist error is gone though. – nilakantha singh deo Mar 16 '18 at 08:25
0

@ethertest ,I have formatted your code as below.Hope it works.

const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
let businessNetworkConnection = new BusinessNetworkConnection();

return businessNetworkConnection.connect('admin@health-network')
.then((bconnect) => {
    let bfactory = bconnect.getFactory();

    return Promise.all([businessNetworkConnection.getParticipantRegistry('org.acme.health.Patient'), bfactory]);
})
.then((participantRegistry1) => {
    participantRegistry = participantRegistry1[0];
    bfactory = participantRegistry1[1];

    let participant = bfactory.newResource('org.acme.biznet', 'Patient', 'patient1');
    participant.firstName = 'Bob';
    participant.lastName = 'Miller';
    return participantRegistry.add(participant);
})
.then(() => {
    return businessNetworkConnection.disconnect();
})
.catch((error) => {
    console.error(error);
    process.exit(1);
});