How to add a document to a voucher

Guide on adding a document to a voucher and transferring it to file service using GraphQL mutations. Includes example queries and notes on limitations.

You can add a document to a voucher by running the the AddNewDocument processing on the Voucher table.

The following query adds a document to an existing voucher:

mutation upload_voucher_document(
        $cid: Int!,
        $batchNo : Int!,
        $voucherNo: Int!,
        $fileName: String!,
        $description: String!,
        $data: String!)
{
  useCompany(no: $cid) {   
    voucher_processings {
      addNewDocument(
        filter: {_and:[
          {batchNo : {_eq : $batchNo}},
          {voucherNo : {_eq : $voucherNo}}
        ]},
      args: {
        fileName : $fileName,
        description : $description,
        fileBytes : $data
      })
      {
        succeeded        
      }
    }
  }
}

Note

The content of the document must be provided as a base64 encoded string.

Note

Beware there is a limit to the raw size of a request. Currently, this is set at 15MB. This limit may be prone to future changes.

Transfering a document to the file service

Documents attached using the Voucher.AddNewDocument processing are stored in the database. If you want to transfer the document to the file service, you can use the UploadToFileService processing on the IncomingAccountingDocumentAttachment table, as shown in the following example:

mutation move_attachment_to_fileservice(
   $cid: Int, 
   $fileName: String,
   $tok: String)
{
  useCompany(no: $cid)
  {
    incomingAccountingDocumentAttachment_processings
    {
      uploadToFileService(
        filter: {fileName: {_eq: $fileName}},
        args: {
          connectToken: $tok
        }
      )
      {
        succeeded
      }
    }
  }
}

The argument connectToken requires a valid Visma Connect access token. This is the same token you use to authenticate your requests to the Business NXT API.

You can execute these two processings sequentially, in a single request.

mutation upload_voucher_document(
        $cid: Int!,
        $batchNo : Int!,
        $voucherNo: Int!,
        $fileName: String!,
        $description: String!,
        $data: String!,
        $tok: String)
{
  useCompany(no: $cid) {   
    voucher_processings {
      addNewDocument(
        filter: {_and:[
          {batchNo : {_eq : $batchNo}},
          {voucherNo : {_eq : $voucherNo}}
        ]},
      args: {
        fileName : $fileName,
        description : $description,
        fileBytes : $data
      })
      {
        succeeded        
      }
    }

    incomingAccountingDocumentAttachment_processings
    {
      uploadToFileService(
        filter: {fileName: {_eq: $fileName}},
        args: {
          connectToken: $tok
        }
      )
      {
        succeeded
      }
    }
  }
}

Note

In the future, the Voucher.AddNewDocument processing may be updated to transfer the document to the file service directly without needing to execute the second processing explicitly.

Last modified September 24, 2024