Create Script Expressions, Tasks and Classes.

TutorialsScripts | Tutorial | How-to Guide | Reference


This Tutorial Teaches you to:

  • Create calculated tags using expressions
  • Build reusable logic with Script Classes
  • Automate processes with Script Tasks
  • Handle events and data transformations
  • Monitor script performance and debugging

Prerequisites:


1. Create Tag Expressions

  1. Navigate to Scripts → Expressions
  2. Add temperature conversion:
FieldValue
ObjectTag.Tank1_TempF (create as Double)
ExpressionTag.Tank1_Temp * 1.8 + 32
ExecutionOnChange
DomainServer

Add status logic:

FieldValue
ObjectTag.System_Status (create as String)
ExpressionTIF(Tag.Tank1_Status = 2, "Running", "Stopped")
ExecutionOnChange
DomainServer

2. Create Script Task

  1. Go to Scripts → Tasks
  2. Click plus icon, name: ShiftCounter
  3. Choose language CSharp
  4. Press OK
  5. Use Server.DateTimeInfo.Hour as Trigger
  6. Double-click to open Code Editor
  7. Enter code (no method wrapper):


// Reset counter at shift change
int hour = @Server.DateTimeInfo.Hour;
if (hour == 6 || hour == 14 || hour == 22)
{
        @Tag.Units_Previous = @Tag.Units_Produced;
        @Tag.Units_Produced = 0;
}

3. Build Script Class

  1. Navigate to Scripts → Classes
  2. Create class: TankCalculations
  3. Enter methods (no class declaration):


public double CalculateVolume(double level, double diameter)
{
    double radius = diameter / 2;
    return Math.PI * radius * radius * level;
}

public double CalculateFlowRate(double volumeStart, double volumeEnd, int minutes)
{
    if (minutes == 0) return 0;
       return (volumeEnd - volumeStart) / minutes;
}

public string GetStatusText(double value, double limit)
{
    if (value > limit)
        return $"High: {value:F2} (Limit: {limit:F2})";
    else
        return "Normal";
}

4. Use Class in Expression

  1. Go to Scripts → Expressions
  2. Create volume calculation:
FieldValue
ObjectTag.Tank1_Volume
ExpressionScript.Class.TankCalculations.CalculateVolume(Tag.Tank1_Level, 10.5)
ExecutionOnChange

Note: No @ symbol needed in expressions



Test and Debug

  1. Build verification:
    • Check green checkmark in BuildStatus
    • Review BuildErrors if red X
  2. Runtime monitoring:
    • Go to Scripts → Scripts Monitor
    • Check Counter
    • Review LastRun
  3. Debug with breakpoints:


Explanation - to understand concepts

Modules / Business Operations / Scripts Module

Tutorials - to learn by doing

Tutorials /  Business Operations / Scripts Module Tutorial

How-to Guides - to accomplish specific tasks

How-to Guides / I Business Operations / Scripts Module How-to Guide

Reference - technical details

Technical Reference /  Business Operations / Scripts Module Reference



In this section...