1
contract Testing {
    struct FormData {
        bool approved;
        address[] submitters;
        address[] approvers;
        uint256 numConfirmationsRequired;
        string formStatus;
    }
    mapping(uint256 => FormData) public formIdToFormData;
function setFormData(uint256 _formId, bool _approved, address[] memory _submitters, address[] memory _approvers, uint256 _numConfirmationsRequired, string memory _formStatus) public {
        require(_submitters.length > 0, "Submitters array must not be empty");
    require(_approvers.length > 0, "Approvers array must not be empty");


    formIdToFormData[_formId].approved = _approved;
    formIdToFormData[_formId].submitters = _submitters;
    formIdToFormData[_formId].approvers = _approvers;
    formIdToFormData[_formId].numConfirmationsRequired = _numConfirmationsRequired;
    formIdToFormData[_formId].formStatus = _formStatus;
}
}
4
  • Are you sure the transaction has completed? If they aren't set then the transaction could have failed, run out of gas or reverted for some reason, or there wasn't a transaction. Where are you testing? public testnet or a test node like ganache.
    – Ismael
    Mar 15, 2023 at 17:15
  • Hello @Ismael, I am writing this code in Remix . How can I be sure that the transaction has been completed ? Every other field in struct is getting set except the arrays . I deployed the contract here : 0x6Aa1EAC0BD5ca34d815B283c3fdfE59CCe4eaC13 ( polygon mumbai ) . I believe this error or whatever I say is because we can't put array inside a struct in solidity ?? I am new to solidity , have you ever used array inside of a struct and a mapping like formIdToFormData above to get and set the struct fields ? Mar 15, 2023 at 17:33
  • It is not possible for a transaction to save some values and not others. Either, it saves all, or it doesn't save anything. How are you checking the submitters and approvers were saved correctly? Just be aware that the getter for formIdToFormData doesn't return dynamic fields like arrays or mappings.
    – Ismael
    Mar 15, 2023 at 18:16
  • " Just be aware that the getter for formIdToFormData doesn't return dynamic fields like arrays or mappings. " Found the culprit . I was using getter to get array values . How can I check that the submitters and approvers were saved correctly ? Mar 15, 2023 at 18:28

1 Answer 1

1

Be aware that the default getter for formIdToFormData doesn't return the dynamic fields like arrays or mappings.

In order to access the FormData you could define your own getter. Something like this:

function getFormData(uint256 _id) public view returns (FormData memory) {
    return formIdToFormData[_id];
}
1
  • Thanks Ismael . I was going mad by seeing the result of default getter . Mar 16, 2023 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.