Skip to content
Developerhome
Sage Distribution and Manufacturing Operations

Mutation: Bulk update

  Less than to read

A bulk update mutation allows updating several properties in several records.

The following table displays an example and the result of a mutation to perform a bulk update. Some of the fields displayed are not mandatory, and others have been omitted.

mutation {
  xtremMasterData {
    item {
      bulkUpdate(
        data: {minimumSalesQuantity: 10}
        filter: "{salesUnit:{name:{_eq:'Each'}}}"
      )
    }
  }
}
{
  "data": {
    "xtremMasterData": {
      "customer": {
        "bulkUpdate": true
      }
    }
  },
  "extensions": {
    "diagnoses": []
  }
} 

This type of mutation is executed on a potentially vast number of records. Because of that, it can fail in timeout, as it is a unique transaction. In the event of failure, a rollback is performed.

A bulk update also allows to assign several properties on the header of a document.

In a vital collection, you can use bulk updates to apply various actions such as add, delete, and update on multiple lines as with the query example shown below. Some of the fields displayed are not mandatory and others have been omitted.

mutation {
  xtremSales {
    salesOrder {
      update(
        data: {_id: "20059",
          lines: [
            {_id: "1000099079", _action: "delete"},
            {_id: "1000099080", _action: "update", quantityInSalesUnit: "50"},
            {_id: "-1", _action: "create", item: "#CHERRY_PIE", quantityInSalesUnit: 27, grossPrice: 8.44, stockSite: "#S01-FR"}
          ]}
      ) {
        lines {
          query {
            edges {
              node {
                _sortValue
                itemId
                itemDescription
                grossPrice
                _updateStamp
              }
            }
          }
        }
      }
    }
  }
}
{
  "data": {
    "xtremSales": {
      "salesOrder": {
        "update": {
          "lines": {
            "query": {
              "edges": [
                {
                  "node": {
                    "_sortValue": 20,
                    "itemId": "APPLE_PIE",
                    "grossPrice": "3.16"
                  }
                },
                {
                  "node": {
                    "_sortValue": 30,
                    "itemId": "CHERRY_PIE",
                    "grossPrice": "8.35"
                  }
                },
                {
                  "node": {
                    "_sortValue": 40,
                    "itemId": "CHERRY_PIE",
                    "grossPrice": "8.35"
                  }
                }
              ]
            }
          }
        }
      }
    }
  },
  "extensions": {
    "diagnoses": []
  }
}

For an operation like the one above, the _id is necessary for the header and every updated line.

To create lines, a negative _id is requested and it will be automotically reassigned by the system afterwards.