Generating new values from other existing values is achievable using the scripting tool in Designer. Designer uses a publish-subscribe approach to read existing values and create new ones. The following tutorial shows how to subscribe to two existing fields (Pass Counts and Fail Counts) to publish a new value (Fail Ratio)
1. Take note of the name of the items that you want to subscribe to.

2. Create a virtual item as the placeholder for the new value and add it as an "item" to your app.


3. Create a Local Script (JavaScript file), click "Edit selected entry".

4. Replace the content with the following code:
(function () {
var MODULE_NAME = "generate_new_value",
ENABLE_LOGGING = true,
RECORD_LOG = false,
logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME, ENABLE_LOGGING, RECORD_LOG),
fLog = logger.fLog,
log = logger.log,
module = shmi.pkg( MODULE_NAME );
module.run = function (self) {
im = shmi.requires("visuals.session.ItemManager"), // Get reference to ItemManager instance
tok = null;
// Define variables
hFailCount = hPassCount = lFailCount = lPassCount = wFailCount = wPassCount =
hFailRate = lFailRate = wFailRate = 0,
items = ["Height Fail Count", "Height Pass Count", "Length Fail Count",
"Length Pass Count", "Width Fail Count", "Width Pass Count"];
// Subscribe items. In this example 6 items are subscribed to.
tok = im.subscribe(items, (name, value, type) => { //values callback
if (name === "Height Fail Count") hFailCount += value;
if (name === "Height Pass Count") hPassCount += value;
if (name === "Length Fail Count") lFailCount += value;
if (name === "Length Pass Count") lPassCount += value;
if (name === "Width Fail Count") wFailCount += value;
if (name === "Width Pass Count") wPassCount += value;
// Publish new items.
// writeValue(name, value) Writes "value" to an item matching the specified "name"
im.writeValue("virtual:HeightFailRate", hFailCount / (hFailCount + hPassCount) * 100);
im.writeValue("virtual:LengthFailRate", lFailCount / (lFailCount + lPassCount) * 100);
im.writeValue("virtual:WidthFailRate", wFailCount / (wFailCount + wPassCount) * 100);
// console.log(`item '${name}': ${value} (${type})}`);
}, (name, properties) => { // properties callback
// console.log(`item '${name}': ${JSON.stringify(properties, null, 4)}`);
});
// Unsubscribe items when the script is not active anymore.
self.onDisable = function () {
tok.unlisten()
self.run = false;
};
};
fLog("module loaded");
})();
4. Add a Local Script widget to the desired page.

5. With the widget selected, go to Config and add the newly created JavaScript File. Now the script is automatically run when the user navigates to the page where you added the Local Script widget.
