Update Batch Production Records

  • Inserts, updates or replaces new or existing batch production record and/or it’s sub documents.

  • For updating Batch Production Records stored in the default system Production Tracking data store, access to the equipment model is required.

  • For updating Batch Production Records stored in a custom Production Tracking data store, WRITE permission on the data store object is required.

  • HTTP methods supported: POST.

Description

The update batch production records endpoint allows update, replace or insert a new Batch Production Record (BRP). The endpoint logic makes use of the Lua function isa88.db.update().

Parameters

Name Type Optional Description

body

body

no

A list of BPR update items. Each item in the list should represent one 'update' operation.

data_store

long / string

depends

Specifies a data store. If not specified, this defaults to the System Production Tracking Data Store for Master Cores. For Local Cores, this option is required.The value is an inmation object ID or path, identifying the System object or a custom store object.

wait_for_completion

boolean

yes

Option to force the server to just queue the MongoDB operations and return as quickly as possible. In this case the outcome of the annotate operations will not be part of the response.

fields

string

yes

Comma separated string to customize which fields should be included in the response, by default 'n,update_id'. Supported fields are c = MassStatusCode, n = MassStatusName, update_id = Identifier which can be matched later with the results published by the BPR Publisher class. Provide ALL to include all fields.

insights

boolean

yes

Indicates application insights should be included in the response, by default false.

BPR update item

Should be a valid JSON document representing a single 'update' operation to perform. The following fields are supported:

  • doc
    Doc is a mandatory argument, which must represent a valid S88 document (a BatchProductionRecord, Comment, Sample, etc.).

  • doc_type
    Specifies the S88 document type of the doc argument. Optional, by default 'BatchProductionrecord'.

  • filter
    Filter used to match documents for 'update' and 'replace operations'.

  • filter_type
    Specifies the S88 document type of the filter argument. Optional, by default 'BatchProductionrecord'.

  • bpr
    Specifies a filter for the attributes of a Batch Production Record. This option can be used to further constrain the parent or filter option to the set of matched documents.

  • upsert
    For update or replace operations, inserts the document if upsert = true and filter does not match any documents. Only applies to updating or replacing full Batch Production Record documents.

  • multi
    For update operations, updates all documents that match the filter if multi = true. Otherwise, updates at most one document. For replace operations, removes all documents that match the filter if multi = true. Otherwise, the replace operation fails if more than one document matches. This options is currently not supported and ignored for insert operations. Optional, by default false.

  • operation
    Supported operations are insert (0 or 'insert'), replace (1 or 'replace') and update (2 or 'update') Optional, default operation is insert.

  • parent
    Used to match the parent documents for 'insert' operation'.

  • parent_type
    Specifies the S88 document type of the parent argument. Optional, by default 'BatchProductionrecord'.

  • validate_refs
    If true, DataReference attributes in Change and Comment documents are validated. The validation is performed in memory if a new stand-alone BPR with Embedded Change or Comment sub-documents is inserted. Otherwise, DataReference attributes are validated by checking the existence of the referenced document attribute in the database. Optional, by default false.

  • wait_for_completion
    Option to force the server to just queue the MongoDB operations and return as quickly as possible. If set to false the outcome of the update operations will not be part of the response. Optional, by default true.

Response structure

The response structure is the same as the response structure of the mass endpoint. The items in the response contain an update_id field, which can be matched later with the results published by the BPR Publisher class.

Examples

Insert a new BatchProductionRecord document

This example inserts a new stand-alone Batch Production Record:

HTTP POST

Request URL
  • /api/v2/updatebatchproductionrecords

Request body
{
    "items": [
        {
            "doc": {
                "BatchID": "insert-bpr-01",
                "EquipmentID": "/A/B",
                "ControlRecipes": {
                    "ID": "CR-01"
                }
            },
            "doc_type": "BatchProductionRecord",
            "operation": 0,
            "wait_for_completion": true
        }
    ]
}
Response body
{
  "data": {
    "items": [
      {
        "n": "CREATED",
        "update_id": "89d318c4-3e6a-43fa-8ef3-244994dcca58"
      }
    ],
    "stats": {
      "failure": 0,
      "success": 1,
      "total": 1
    }
  }
}

Insert a Comment into an existing BatchProductionRecord document

This example inserts a new Comment sub-document into an existing Batch Production Record.

HTTP POST

Request URL
  • /api/v2/updatebatchproductionrecords

Request body
{
    "items": [
        {
            "doc": {
                "Comment": "pipe repaired",
                "PersonID" : "My name",
                "TimeStamp" : "2019-09-01T00:00:00.000Z"
            },
            "doc_type": "Comment",
            "parent": {
                "BatchID": "insert-bpr-01"
            },
            "parent_type" : "BatchProductionRecord",
            "operation": "insert",
            "wait_for_completion": true
        }
    ]
}
Response body

The response body has the same structure as in the Insert BatchProduction Record example.

Insert a RecipeElement into an existing ControlRecipe document

This example inserts a new RecipeElement sub-document into an existing Batch Production Record, specifying its direct parent control recipe.

HTTP POST

Request URL
  • /api/v2/updatebatchproductionrecords

Request body
{
    "items": [
        {
            "doc": {
                "ID": "RE-01",
                "RecipeElementType": "PHASE"
            },
            "doc_type": "RecipeElement",
            "bpr": {
                "BatchID": "insert-bpr-01"
            },
            "parent": {
                "ID": "CR-01"
            },
            "parent_type": "ControlRecipe",
            "operation": "insert",
            "wait_for_completion": true
        }
    ]
}
Response body

The response body has the same structure as in the Insert BatchProduction Record example.

Error due to an ambiguous parent

This example tries to insert a new ControlRecipe sub-document into an existing Batch Production Record but fails because a parent document can’t be found unambiguously.

HTTP POST

Request URL
  • /api/v2/updatebatchproductionrecords

Request body
{
    "items": [
        {
            "doc": {
                "ID": "CR-01"
            },
            "doc_type": "ControlRecipe",
            "parent": {
                "LotID": "insert-bpr-01"
            },
            "parent_type": "BatchProductionRecord",
            "operation": "insert",
            "wait_for_completion": true
        }
    ]
}
Response body

If there is more than one BatchProductionRecord with the LotID specified, the call fails with the message ambiguous parent.

{
  "data": {
    "items": [
      {
        "error": {
          "code": 6,
          "msg": "ambiguous parent"
        },
        "n": "FAILED_DENIED"
      }
    ],
    "stats": {
      "failure": 1,
      "success": 0,
      "total": 1
    }
  }
}

It can be fixed either by modifying the parent option or by specifying the bpr option to make it possible to find the parent document unambiguously.

{
    "items": [
        {
            "doc": {
                "ID": "CR-01"
            },
            "doc_type": "ControlRecipe",
            "bpr": {
                "EntryID": "82124a5c-c402-11e9-8b93-a0f3c16f6109"
            },
            "parent": {
                "LotID": "insert-bpr-01"
            },
            "parent_type": "BatchProductionRecord",
            "operation": "insert",
            "wait_for_completion": true
        }
    ]
}

Update a Batch Production Record example by adding a Lot ID.

HTTP POST

Request URL
  • /api/v2/updatebatchproductionrecords

Request body
{
    "items": [
        {
            "doc": {
                "LotID": "lot-0001"
            },
            "doc_type": "BatchProductionRecord",
            "filter": {
                "BatchID": "insert-bpr-01"
            },
            "operation": "update",
            "wait_for_completion": true
        }
    ]
}
Response body

The response body has the same structure as in the Insert BatchProduction Record example.

Update the description of Control Recipe documents.

This example updates the description of all Control Recipe documents of batch production records which contain the specified BatchID. This example uses an empty filter document and the multi options is set to true.

HTTP POST

Request URL
  • /api/v2/updatebatchproductionrecords

Request body
{
    "items": [
        {
            "doc": {
                "Description": "Imported control recipe"
            },
            "doc_type": "ControlRecipe",
            "filter": {},
            "multi" : true,
            "operation": "update",
            "wait_for_completion": true
        }
    ]
}
Response body

The response body has the same structure as in the Insert BatchProduction Record example.

Replace a Batch Production Record

This example replaces all Batch Production Records which match the specified filter with the specified record. If no records match the filter, the record is inserted.

HTTP POST

Request URL
  • /api/v2/updatebatchproductionrecords

Request body
{
    "items": [
        {
            "doc": {
                "BatchID": "BPR-002"
            },
            "doc_type": "BatchProductionRecord",
            "filter": {
                "BatchID": "BPR-001"
            },
            "multi": true,
            "upsert": true,
            "operation": "replace",
            "wait_for_completion": true
        }
    ]
}
Response body

The response body has the same structure as in the Insert BatchProduction Record example.