How to create and finish an order
You need to perform the following GraphQL requests, in this order:
1. Create a new order and lines
The minimum information for the order head you must provide is:
| Field | Type | Description | 
|---|---|---|
| orderDate | int | The date of the order. An integer in the form yyyymmdd. For instance, 23 March 2022, is 20220323. | 
| customerNo | int | The number identifying the customer in Business NXT. (Do not confuse this with the Visma.net customer number!) | 
The minimum information you must provide for each order line is:
| Field | Type | Description | 
|---|---|---|
| productNo | int | The number identifying the product in the system. | 
| quantity | int | The quantity of items that you want to add. | 
Use the following mutation to create an order and its lines:
mutation create_order($cid : Int!,
                      $cno : Int!,
                      $date : Int,
                      $pno1 : String,
                      $pno2 : String)
{
   useCompany(no : $cid)
   {
      order_create(values:[
      {
         orderDate : $date
         customerNo : $cno
         orderLines : [
            {
               productNo : $pno1
               quantity : 1
            },
            {
               productNo : $pno2
               quantity : 2
            }
         ]
      }])
      {
         affectedRows
         items
         {
            orderNo
            orderDate
            orderLines : joindown_OrderLine_via_Order
            {
               items
               {
                  lineNo
                  productNo
                  quantity
                  priceInCurrency
               }
            }
         }
      }
   }
}{
  "data": {
    "useCompany": {
      "order_create": {
        "affectedRows": 1,
        "items": [
          {
            "orderNo": 439,
            "orderDate": 20250917
            "orderLines": {
              "items": [
                {
                  "lineNo": 1,
                  "productNo": "HW1",
                  "quantity": 1,
                  "priceInCurrency": 100
                },
                {
                  "lineNo": 2,
                  "productNo": "AGG4",
                  "quantity": 2,
                  "priceInCurrency": 75
                }
              ]
            }
          }
        ]
      }
    }
  }
}2. Finishing an order
The minimum information you need to finish an order is the order number.
Use a mutation with the order_processings field to execute a processing on an order. To finish the order, use the finish field:
mutation finish_order($cid : Int!,
                      $ono : Int!)
{
  useCompany(no : $cid)
  {
    order_processings
    {
      finish(filter: {orderNo:{_eq : $ono}})
      {
        succeeded
        items
        {
          handledOrderLine
          {
            lineNo
            finishedNow
          }
        }
      }
    }
  }
}{
  "data": {
    "useCompany": {
      "order_processings": {
        "finish": {
          "succeeded": true,
          "items": [
            {
              "handledOrderLine": [
                {
                  "lineNo": 1,
                  "finishedNow": 1
                },
                {
                  "lineNo": 2,
                  "finishedNow": 2
                }
              ]
            }
          ]
        }
      }
    }
  }
}Finishing parameters
The finish processing has a parameter called finishType that is an integer defining what the processing should do.
The implicit value is 0 which means the whole order should be finished. This is what we have seen in the previous example, where the argument was missing, therefore its default value was used.
The possible values for finishType are:
| Value | Description | 
|---|---|
| 0 | Finish the whole order. | 
| 1 | Finish the articles specified by their barcode. | 
| 2 | Finish the articles specified by their product number. | 
| 3 | Finish the articles specified by their TransactionInformation1field. | 
Alternatively, you can use the finishTypeAsEnum field, that enables you to use a enumeration value, instead of a numerical one. The possible values are:
| Name | Value | 
|---|---|
| WholeOrder | 0 | 
| Barcode | 1 | 
| ProductNumber | 2 | 
| TransactionInformation1 | 3 | 
When finishType has any other value than 0, then you need to provide the additional arguments using the group parameter. This is a dictionary of key-value pairs, where the key is the bar code, product number, or the TransactionInformation1 value of a product, and value is the quantity to finish (remove from the order).
mutation finish_order($cid : Int!,
                      $ono : Int!)
{
  useCompany(no : $cid)
  {
    order_processings
    {
      finish(
        args : {
          finishTypeAsEnum : ProductNumber
          group : [
            {key: "HW1",  quantity: 2},
            {key: "AGG4", quantity: 5}
          ]
        },
        filter: {orderNo:{_eq : $ono}}
      )
      {
        succeeded
        items
        {
          handledOrderLine
          {
            lineNo
            finishedNow
          }
        }
      }
    }
  }
}{
  "data": {
    "useCompany": {
      "order_processings": {
        "finish": {
          "succeeded": true,
          "items": [
            {
              "handledOrderLine": [
                {
                  "lineNo": 1,
                  "finishedNow": 2
                },
                {
                  "lineNo": 2,
                  "finishedNow": 5
                }
              ]
            }
          ]
        }
      }
    }
  }
}Alternatives for creating an order and order lines
The obsolete way of creating an order and its lines is to do it in two separate requests. First, you create the order head, and then you add the order lines.
1. Two separate requests
Use a mutation with the order_create field to add a new order:
mutation create_order($cid : Int!,
                      $cno : Int!,
                      $date : Int)
{
  useCompany(no : $cid)
  {
    order_create(values:[{
      orderDate : $date
      customerNo : $cno
    }])
    {
      affectedRows
      items
      {
        orderNo
        orderDate
      }
    }
  }
}{
  "data": {
    "useCompany": {
      "order_create": {
        "affectedRows": 1,
        "items": [
          {
              "orderNo": 439,
              "orderDate": 20220401
          }
        ]
      }
    }
  }
}From the result, you must use the orderNo to add order lines. Then, use a mutation with the orderLine_create field to add one or more order lines:
mutation create_order_line($cid : Int!,
                           $ono : Int!,
                           $pno1 : String,
                           $pno2 : String)
{
  useCompany(no : $cid)
  {
    orderLine_create(values:[
      {
        orderNo : $ono
        productNo : $pno1
        quantity : 1
      },
      {
        orderNo : $ono
        productNo : $pno2
        quantity : 2
      },
    ])
    {
      affectedRows
      items
      {
        lineNo
      }
    }
  }
}{
  "data": {
    "useCompany": {
      "orderLine_create": {
        "affectedRows": 2,
        "items": [
          {
            "lineNo": 1
          },
          {
            "lineNo": 2
          }
        ]
      }
    }
  }
}2. One request using the @export directive
You can create both an order and its order lines with a single request, using the @export directive. This directive allows you to capture the value of an evaluated field into a variable that can be used later in the query.
mutation create_order_and_line($cid : Int!,
                               $cno : Int!,
                               $date : Int
                               $pno1 : String,
                               $pno2 : String,
                               $ono : Int = 0)
{
  useCompany(no : $cid)
  {
    # create the order first
    order_create(values:[{
      orderDate : $date
      customerNo : $cno
    }])
    {
      affectedRows
      items
      {
        # capture the value of the orderNo field
        # into the ono variable
        orderNo @export(as: "ono")
        orderDate
      }
    }
    # create the order lines
    orderLine_create(values:[
      {
        orderNo : $ono
        productNo : $pno1
        quantity : 1
      },
      {
        orderNo : $ono
        productNo : $pno2
        quantity : 2
      },
    ])
    {
      affectedRows
      items
      {
        orderNo
        lineNo
      }
    }
  }
}{
  "data": {
    "useCompany": {
      "order_create": {
        "affectedRows": 1,
        "items": [
          {
              "orderNo": 440,
              "orderDate": 20221122
          }
        ]
      },
      "orderLine_create": {
        "affectedRows": 2,
        "items": [
          {
            "orderNo": 440,
            "lineNo": 1
          },
          {
            "orderNo": 440,
            "lineNo": 2
          }
        ]
      }
    }
  }
}