Batch Production Record Data in Reports
Batch Production Record data can be incorporated into reports using Lua via the methods in the inmation.report
library. The isa88todataset()
method converts isa88 batch production record data from the Production Tracking Data Store to a Lua table, where it can be encoded to JSON format to be used by the reporting tools.
The Lua script can be added to the Lua Script Body property of a report item.
To query the Production Tracking Data Store you can use the isa88.db.find() method from the isa88 Lua library. The below example demonstrates this and uses the rapidjson Lua library is used to encode the returned JSON string for the report.
local isa88 = require "isa88"
local report = require("inmation.report")
local JSON = require("rapidjson")
local options = {}
options.limit = 1
--find any Batch Production Record
local array = isa88.db.find([[
[
{
"BatchProductionRecord": {
"ID": {"$regex": "","$options": ""}
}
}
]
]], options)
if array ~= nill and #array > 0 then
local bpr = array[1].BatchProductionRecords
if bpr ~= nil then
-- If the second parameter of isa88todataset() call is true then all arrays are truncated to 5 elements.
-- Truncating of arrays helps to create smaller json documents usable as a "report design time data".
local result = report:isa88todataset(bpr, false)
return JSON.encode(result)
else
return "<no bpr data available>"
end
end