I have the following simple structure and array of that structure:
struct Document {
bytes32 ownerID;
bytes32 documentID;
bytes32 name;
}
Document[] public documents;
I've a storeDoc() method that fills up the array:
function storeDocument (bytes32 _ownerID , bytes32 _documentID, bytes32 _name) {
Document memory newDoc;
newDoc.ownerID = _ownerID;
newDoc.documentID = _documentID;
newDoc.name = _name;
documents.push(newDoc);
}
And finally a getter. There could be multiple entries against one OwenerID, thus the memory arrays:
function getDocumentDetailsByID(bytes32 _ownerID) constant public returns (bytes32[], bytes32[], bytes32[]) {
uint length = documents.length;
if(registeredCandidates[_ownerID].clientAddress == msg.sender) {
bytes32[] memory documentIDs = new bytes32[](length);
bytes32[] memory names = new bytes32[](length);
bytes32[] memory descriptions = new bytes32[](length);
bytes32[] memory docYears = new bytes32[](length);
for(uint i =0; i < length; i++) {
if(documents[i].ownerID == _ownerID) {
Document memory currentDocument;
currentDocument = documents[i];
documentIDs[i] = currentDocument.documentID;
names[i] = currentDocument.name;
}
}
return (documentIDs, names);
} else {
return;
}
}
The problem I face is that only the first entry done by the storeDocument() returns using getDocumentDetailsByID() properly.
The second onward entries done by storeDocument() is coming as all zeros when I call the getDocumentDetailsByID() for the second time!!
Could someone please guide me what's I'm doing wrong? Thanks.