Scripts in Web Port can be used in many places. It adds support for advanced functionality and customization. Web Port uses a scripting engine that allows for server side scripts to be run both in the background and on request. The engine supports a mix of .NET and JavaScript features. The engine also have access to data in Web Port through supplied variables and functions.
Script types
Call scripts
Call scripts are run on request. This could be because a user pushes a button, an alarm rule calls the script or it is called by an API-call.
Looped scripts
Looped scripts run on a fixed interval that is configured on the script. This is useful for recurring tasks, like calculating and updating disk tags, doing exports to external systems etc.
Triggered scripts
Triggered scripts run when a condition is met. This could be an alarm going off, a tag value being greater or smaller than some set value.
Custom reports
Custom reports allows for both a scripting layer and a presentation layer to work together. The script provides the data to the presentation layer, and the presentation layer shows information to the user. For more information read the chapter about custom reports.
Schedule scripts
Schedule scripts are run to encode and decode Web Port schedules to match schedules in different types of controllers. There are read and write functions within the schedule scripts that are called when Web Port updates its schedule.
Inline scripts
There is also support for inline scripts that can be executed from both tags and lib objects. This can be used to quickly do a calculation without having to create a full script.
Best practises
WebPortCommon Assembly
All public types from the ScriptManager assembly (WebPortCommon) are exposed, including:
- Manager classes (TagManager, LibManager, PageManager, DeviceManager, etc.)
- Other public classes in the assembly
Tag Management
- tags— TagManager.Manager.Tags collection
- tagRead(tagName)— Read a tag value
- tagValue(tagName)— Get tag value
- tagWrite(tagName, value)— Write to a tag
Trend & Alarm Data
- getTrendData(tagName, startDate, endDate)— Get trend data
- getActiveAlarmList(includeAcknowledged)— Get active alarms
Debugging
- debug(message)— Log debug message
- console.log(message)— Console logging
Supported .NET features
System Namespaces (mscorlib)
✔ System
✔ System.Text
✔ System.Globalization
✔ System.Collections.Generic
✔ System.Data Namespaces
✔ System.Data
✔ System.Data.SqlClient
✔ System.Net Namespaces
✔ System.Net
✔ System.Net.Http
✔ System.Text.RegularExpressions
✔ System.Web Namespace
✔ System.Web
Newtonsoft.Json Namespaces
✔ Newtonsoft.Json
✔ Newtonsoft.Json.Linq
✔ Newtonsoft.Json.Converters
File System Types
- File— SafeFileWrapper
- Directory— SafeDirectoryWrapper
- FileInfo— SafeFileInfoWrapper
- StreamWriter— SafeStreamWriter
- StreamReader— SafeStreamReader
- ZipFileExtensions— SafeZipFileExtensionsWrapper
Standard .NET Types
- Path— System.IO.Path
- MemoryStream— System.IO.MemoryStream
- ZipArchive— System.IO.Compression.ZipArchive
- ZipArchiveMode— System.IO.Compression.ZipArchiveMode enum
- SearchOption— System.IO.SearchOption enum
Special Type Handling
- Enum— Exposed via EnumWrapper (GetNames, GetValues, Parse methods)
- String— Special prototype handling to avoid conflicts
- DateTime— Custom converter for proper JavaScript interop
Utility Functions
- Sleep(milliseconds)— Thread sleep
- ToDotNetString(obj, args)— Convert object to string
- Object.prototype.ToString(...args)— Extended ToString on all objects
Supported JavaScript features
ECMAScript 2015 (ES6)
✔ ArrayBuffer
✔ Arrow function expression
✔ Binary and octal literals
✔ Class support
✔ DataView
✔ Destructuring
✔ Default, rest and spread
✔ Enhanced object literals
✔ for...of
❌ Generators
✔ Template strings
✔ Lexical scoping of variables (let and const)
✔ Map and Set
✔ Modules and module loaders
✔ Promises (Experimental, API is unstable)
✔ Reflect
✔ Proxies
✔ Symbols
❌ Tail calls
✔ Typed arrays
✔ Unicode
✔ Weakmap and Weakset
ECMAScript 2016
✔ Array.prototype.includes
✔ await, async
✔ Block-scoping of variables and functions
✔ Exponentiation operator **
✔ Destructuring patterns (of variables)
ECMAScript 2017
✔ Object.values, Object.entries and Object.getOwnPropertyDescriptors
❌ Shared memory and atomics
ECMAScript 2018
✔ Promise.prototype.finally
✔ RegExp named capture groups
✔ Rest/spread operators for object literals (...identifier)
✔ SharedArrayBuffer
ECMAScript 2019
✔ Array.prototype.flat, Array.prototype.flatMap
✔ String.prototype.trimStart, String.prototype.trimEnd
✔ Object.fromEntries
✔ Symbol.description
✔ Optional catch binding
ECMAScript 2020
✔ BigInt
✔ export * as ns from
✔ for-in enhancements
✔ globalThis object
✔ import
✔ import.meta
✔ Nullish coalescing operator (??)
✔ Optional chaining
✔ Promise.allSettled
✔ String.prototype.matchAll
ECMAScript 2021
✔ Logical Assignment Operators (&&= ||= ??=)
✔ Numeric Separators (1_000)
✔ AggregateError
✔ Promise.any
✔ String.prototype.replaceAll
✔ WeakRef
✔ FinalizationRegistry
ECMAScript 2022
✔ Class Fields
✔ RegExp Match Indices
✔ Top-level await
✔ Ergonomic brand checks for Private Fields
✔ .at()
✔ Accessible Object.prototype.hasOwnProperty (Object.hasOwn)
✔ Class Static Block
✔ Error Cause
ECMAScript 2023
✔ Array find from last
✔ Change Array by copy
✔ Hashbang Grammar
✔ Symbols as WeakMap keys
ECMAScript 2024
✔ ArrayBuffer enhancements - ArrayBuffer.prototype.resize and ArrayBuffer.prototype.transfer
❌ Atomics.waitAsync
✔ Ensuring that strings are well-formed - String.prototype.ensureWellFormed and String.prototype.isWellFormed
✔ Grouping synchronous iterables - Object.groupBy and Map.groupBy
✔ Promise.withResolvers
❌ Regular expression flag /v
ECMAScript 2025
✔ 16-bit floating point numbers (float16), Requires NET 8 or higher, Float16Array, Math.f16round()
✔ Import attributes
❌ Iterator helper methods
✔ JSON modules
✔ Promise.try
❌ RegExp.escape()
❌ Regular expression pattern modifiers (inline flags)
❌ Duplicate named capture groups
✔ Set methods (intersection, union, difference, symmetricDifference, isSubsetOf, isSupersetOf, isDisjointFrom)
ECMAScript Stage 3 or earlier (no version yet)
✔ Error.isError
✔ Explicit Resource Management (using and await using)
✔ Math.sumPrecise
✔ ShadowRealm
✔ Uint8Array to/from base64
✔ Upsert