Utils API
Utils API contains small utility helpers: UUID generation, date, bit operations, number formatting, string padding.
Unique Identifier
Section titled “Unique Identifier”ins.uuid()
Section titled “ins.uuid()”Generates a fresh UUID string.
var id = ins.uuid();// → "f4cbb047-4376-4d8b-ae46-5cafed31155b"ins.now()
Section titled “ins.now()”Returns the server’s current time as a Date.
var n = ins.now();// → Wed Apr 23 00:15:42 TRT 2026ins.getDate(ms)
Section titled “ins.getDate(ms)”Returns the Date that corresponds to the given epoch millisecond.
var yesterday = ins.getDate(Date.now() - 86400000);var oneHourAgo = ins.getDate(Date.now() - 3600000);Bit Operations
Section titled “Bit Operations”ins.getBit(value, bitIndex)
Section titled “ins.getBit(value, bitIndex)”Reads a specific bit (0 = rightmost) from a Long — returns Boolean.
var statusWord = ins.getVariableValue("status_register").value;var bit3 = ins.getBit(statusWord, 3); // true | falseins.setBit(value, bitIndex, bitValue)
Section titled “ins.setBit(value, bitIndex, bitValue)”Flips a specific bit of a Long — returns the new Long (the original is unchanged).
var word = 0;word = ins.setBit(word, 0, true); // bit 0 = 1 → 1word = ins.setBit(word, 3, true); // bit 3 = 1 → 9String and Number Formatting
Section titled “String and Number Formatting”ins.leftPad(str, len, padChar)
Section titled “ins.leftPad(str, len, padChar)”Pads the string on the left with padChar to reach len.
ins.leftPad("42", 5, "0"); // → "00042"ins.leftPad("AB", 4, " "); // → " AB"ins.formatNumber(number, pattern, decimalSeparator, groupingSeparator)
Section titled “ins.formatNumber(number, pattern, decimalSeparator, groupingSeparator)”Formats a number using a Java DecimalFormat pattern.
ins.formatNumber(1234567.89, "#,##0.00", ",", ".");// → "1.234.567,89"
ins.formatNumber(3.14159, "0.00", ".", ",");// → "3.14"