---
title: "How to create and update a batch"
description: "Guide on creating and updating a batch using GraphQL. Includes steps for batch creation, determining voucher number, voucher creation, and batch update."
lang: en
languages:
  en: https://docs.vismasoftware.no/businessnxtapi/examples/howto/batch/index.md
lastmod: 2026-07-10
---

> Documentation index: https://docs.vismasoftware.no/businessnxtapi/examples/howto/llms.txt


# How to create and update a batch

Last modified July 10, 2026

> Guide on creating and updating a batch using GraphQL. Includes steps for batch creation, determining voucher number, voucher creation, and batch update.


You need to perform the following GraphQL requests, in this order:

## 1. Determining the next voucher no

When creating a voucher, you need to provide a voucher number. You can determine this value by reading the `nextVoucherNo` value from the `VoucherSeries` table. To do so, you must provide the `voucherSeriesNo` which should be the same used for creating the batch.

```graphql { title = "Query" }
query read_voucher_series($cid : Int!,
                          $vsn : Int!)
{
   useCompany(no : $cid)
   {
      voucherSeries(filter :
         {
            voucherSeriesNo : {_eq: $vsn}
         }
      )
      {
         totalCount
         items
         {
            voucherSeriesNo
            name
            lastVoucherNo
            nextVoucherNo
         }
      }
   }
}
```

```graphql { title = "Result" }
{
  "data": {
    "useCompany": {
      "voucherSeries": {
        "totalCount": 1,
        "items": [
          {
            "voucherSeriesNo": 6,
            "name": "Diverse bilag",
            "lastVoucherNo": 69999,
            "nextVoucherNo": 60003
          }
        ]
      }
    }
  }
}
```

## 2. Creating a new batch and voucher

The minimum information you need to provide for creating the batch is:

| Field | Type | Description |
| ----- | ---- | ----------- |
| `valueDate` | int | The value date as an integer in the form `yyyymmdd`. For instance, 23 March 2022, is 20220323. |
| `voucherSeriesNo` | int | The number of the voucher series. |

The minimum information you need to provide in order to create a new voucher is:

| Field | Type | Description |
| ----- | ---- | ----------- |
| `voucherNo` | int | The number of the voucher. Use the `nextVoucherNo` value read previously. |
| `debitAccountNo` | int | The debit account number. |
| `creditAccountNo` | int | The credit account number. |
| `amountDomestic` | decimal | The amount value. |
| `voucherDate` | int | The date of the voucher. |
| `valueDate` | int | The value date of the voucher. |

```graphql { title = "Query" }
mutation create_batch_and_voucher($cid : Int!,
                                  $cno : Int!,
                                  $vno : Int!,
                                  $vdt : Int!,
                                  $valuedt : Int!)
{
   useCompany(no : $cid)
   {
      batch_create(values:[
      {
         valueDate : $valuedt

         vouchers : [
            {
               voucherNo : $vno
               debitAccountNo : 1930
               creditAccountNo : $cno
               customerNo : $cno
               amountDomestic : 100
               voucherDate : $vdt
               valueDate : $valuedt
            }
         ]
      }])
      {
         affectedRows
         items 
         {
            batchNo
            valueDate

            vouchers : joindown_Voucher_via_Batch
            {
               items
               {
                  batchNo
                  lineNo

                  voucherNo
                  customerNo
                  debitAccountNo
                  creditAccountNo
                  amountDomestic
                  voucherDate
                  valueDate
               }
            }
         }
      }
   }
}
```

```graphql { title = "Result" }
{
  "data": {
    "useCompany": {
      "batch_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "valueDate": 20251015

            "vouchers": {
              "items": [
                {
                  "batchNo": 1002,
                  "lineNo": 1,
                  "voucherNo": 60003,
                  "customerNo": 10001,
                  "debitAccountNo": 1930,
                  "creditAccountNo": 10001,
                  "amountDomestic": 100,
                  "voucherDate": 20250917,
                  "valueDate": 20251015
                }
              ]
            }
          }
        ]
      }
    }
  }
}
```

### Alternatives for creating a batch and voucher

The _obsolete_ way of creating a batch and vouchers is to do it in two separate requests. First, you create the batch, and then you add the vouchers.

#### 1. Two separate requests

Use a mutation with the `batch_create` field to create a new batch:

```graphql { title = "Query" }
mutation create_batch($cid : Int!,
                      $vsn : Int!,
                      $valuedt : Int!)
{
   useCompany(no : $cid)
   {
      batch_create(values:[
         {
            voucherSeriesNo : $vsn
            valueDate : $valuedt
         }
      ])
      {
         affectedRows
         items
         {
            batchNo
            valueDate
         }
      }
   }
}
```

```graphql { title = "Result" }
{
  "data": {
    "useCompany": {
      "batch_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "valueDate": 20220415
          }
        ]
      }
    }
  }
}
```

You must read and store the `batchNo` in order to use it for creating a voucher. Then, use a mutation with the `voucher_create` field to create a new voucher:

```graphql { title = "Query" }
mutation create_voucher($cid : Int!,
                        $bno : Int!,
                        $cno : Int!,
                        $vno : Int!,
                        $vdt : Int!,
                        $valuedt : Int!)
{
   useCompany(no : $cid)
   {
      voucher_create(values: [
         {
            batchNo : $bno
            voucherNo : $vno
            debitAccountNo : 1930
            creditAccountNo: $cno
            amountDomestic : 100
            voucherDate : $vdt
            valueDate : $valuedt
         }
      ])
      {
         affectedRows
         items
         {
            batchNo
            voucherNo
            voucherDate
            valueDate
         }
      }
}
}
```

```graphql { title = "Result" }
{
  "data": {
    "useCompany": {
      "voucher_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "voucherNo": 60003,
            "voucherDate": 20220323,
            "valueDate": 20220415
          }
        ]
      }
    }
  }
}
```

#### 2. One request using the @export directive

This is possible using the [@export](https://docs.vismasoftware.no/businessnxtapi/apireference/features/directives/index.md#the-export-directive) directive.

```graphql { title = "Query" }
mutation create_batch($cid : Int!,
                      $vsn : Int!,
                      $valuedt : Int!,
                      $cno : Int!,
                      $bno : Int! = 0)
{
   useCompany(no : $cid)
   {
      batch_create(values:[
         {
            voucherSeriesNo : $vsn
            valueDate : $valuedt
         }]
      )
      {
         affectedRows
         items
         {
            batchNo @export(as: "bno")
            valueDate
         }
      }

      voucher_create(values: [
         {
            batchNo : $bno
            voucherNo : null
            debitAccountNo : 1930
            creditAccountNo: $cno
            amountDomestic : 100
            voucherDate : null
            valueDate : $valuedt
         }
      ])
      {
         affectedRows
         items
         {
            batchNo
            voucherNo
            voucherDate
            valueDate
         }
      }
   }
}
```

```graphql { title = "Result" }
{
  "data": {
    "useCompany": {
      "batch_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "valueDate": 20220415
          }
        ]
      },
      "voucher_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "voucherNo": 60003,
            "voucherDate": 20220323,
            "valueDate": 20220415
          }
        ]
      }
    }
  }
}
```

### Create a new voucher with suggested voucher number

Instead of determining the next voucher number in the series you can request that the system figures out the next value for it. You can also do that for other fields, such as voucher date.
This is done with the [Suggest Feature](https://docs.vismasoftware.no/businessnxtapi/apireference/schema/mutations/inserts/index.md#suggested-values).

```graphql { title = "Query" }
mutation create_voucher($cid : Int!,
                        $bno : Int!,
                        $cno : Int!,
                        $valuedt : Int!)
{
   useCompany(no : $cid)
   {
      voucher_create(values: [
         {
            batchNo : $bno
            voucherNo : null
            debitAccountNo : 1930
            creditAccountNo: $cno
            amountDomestic : 100
            voucherDate : null
            valueDate : $valuedt
         }
      ])
      {
         affectedRows
         items
         {
            batchNo
            voucherNo
            voucherDate
            valueDate
         }
      }
   }
}
```

```graphql { title = "Result" }
{
  "data": {
    "useCompany": {
      "voucher_create": {
        "affectedRows": 1,
        "items": [
          {
            "batchNo": 1002,
            "voucherNo": 60003,
            "voucherDate": 20220323,
            "valueDate": 20220415
          }
        ]
      }
    }
  }
}
```

## 3. Updating a batch

The minimum information to update a batch is the batch number.

Use a mutation with the `batch_processings` field to execute processings on the batch table. Use the `updateBatch` field to update the batch:

```graphql { title = "Query" }
mutation update_batch($cid : Int!,
                      $bno : Int!)
{
   useCompany(no : $cid)
   {
      batch_processings
      {
         updateBatch(filter :
           {
             batchNo : {_eq : $bno}
           }
         )
         {
            succeeded
            voucherJournalNo
         }
      }
   }
}
```

```graphql { title = "Result" }
{
  "data": {
    "useCompany": {
      "batch_processings": {
        "updateBatch": {
          "succeeded": true,
          "voucherJournalNo": 193
        }
      }
    }
  }
```


---

[View this page](https://docs.vismasoftware.no/businessnxtapi/examples/howto/batch/)
