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 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 |
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
Forupdate
orreplace
operations, inserts the document ifupsert
= true and filter does not match any documents. Only applies to updating or replacing full Batch Production Record documents. -
multi
Forupdate
operations, updates all documents that match the filter if multi = true. Otherwise, updates at most one document. Forreplace
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 areinsert
(0 or 'insert'),replace
(1 or 'replace') andupdate
(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:
Insert a Comment into an existing BatchProductionRecord document
This example inserts a new Comment sub-document into an existing Batch Production Record.
HTTP POST
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.
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 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.
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.
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.