Add Method (UtilHistory)
- Last UpdatedNov 06, 2025
- 5 minute read
The Add() method can be used to create a record for a new current event, add a record for a past event (effectively splitting an existing event), or update an existing event record in the Util_History table.
When using the Add() method to add a past event, the duration of the new past event will be from the supplied start time to the start time of the next existing event in the event sequence. To create a new past event of a specific duration, use the AddEvent() method.
'Declaration
Public Shared Sub Add( _
ByVal sessionId As Integer, _
ByVal entityId As Integer, _
ByVal eventTimeUtc As Nullable(Of Date), _
ByVal reasonCode As Integer, _
ByVal reasonPending As Nullable(Of Boolean), _
ByVal comments As String, _
ByVal rawReasonCode As String, _
ByVal spare1 As String, _
ByVal spare2 As String, _
ByVal spare3 As String, _
ByVal spare4 As String, _
ByVal category1 As String, _
ByVal category2 As String, _
ByVal category3 As String, _
ByVal category4 As String, _
ByVal updateIfExists As Nullable(Of Boolean), _
ByRef lastEditAt As Nullable(Of Date), _
ByRef recordsAffected As Nullable(Of Integer) _
)
'Usage
Dim sessionId As Integer
Dim entityId As Integer
Dim eventTimeUtc As Nullable(Of Date)
Dim reasonCode As Integer
Dim reasonPending As Nullable(Of Boolean)
Dim comments As String
Dim rawReasonCode As String
Dim spare1 As String
Dim spare2 As String
Dim spare3 As String
Dim spare4 As String
Dim category1 As String
Dim category2 As String
Dim category3 As String
Dim category4 As String
Dim updateIfExists As Nullable(Of Boolean)
Dim lastEditAt As Nullable(Of Date)
Dim recordsAffected As Nullable(Of Integer)
UtilHistory.Add(sessionId, entityId, eventTimeUtc, reasonCode, reasonPending, comments, rawReasonCode, spare1, spare2, spare3, spare4, category1, category2, category3, category4, updateIfExists, lastEditAt, recordsAffected)
public static void Add(
int sessionId,
int entityId,
Nullable<DateTime> eventTimeUtc,
int reasonCode,
Nullable<bool> reasonPending,
string comments,
string rawReasonCode,
string spare1,
string spare2,
string spare3,
string spare4,
string category1,
string category2,
string category3,
string category4,
Nullable<bool> updateIfExists,
out Nullable<DateTime> lastEditAt,
out Nullable<int> recordsAffected
)
Parameters
- sessionId
- Required. Holds the session ID and thus the user who is making this method call.
- entityId
- Required. Holds the ID of the entity to which this utilization event is being added.
- eventTimeUtc
- Optional. Holds the date/time for the start of the utilization event in UTC. The default is the current time.
- reasonCode
- Required. Holds the code that identifies the reason for the utilization event.
- reasonPending
- Optional. Holds a flag that, if true, specifies that the reason is pending and needs to be finalized.
- comments
- Optional. Holds text to describe the event.
- rawReasonCode
- Optional. Holds the code that identifies the raw reason that used to determine the utilization reason.
- spare1
- Optional. Holds the contents of the user-defined spare1 field.
- spare2
- Optional. Holds the contents of the user-defined spare2 field.
- spare3
- Optional. Holds the contents of the user-defined spare3 field.
- spare4
- Optional. Holds the contents of the user-defined spare4 field.
- category1
- Optional. Holds a user defined field that describes category1.
- category2
- Optional. Holds a user defined field that describes category2.
- category3
- Optional. Holds a user defined field that describes category3.
- category4
- Optional. Holds a user defined field that describes category4.
- updateIfExists
Optional. Holds a flag that, if set to true, specifies that if a matching record already exists, it will be updated with the parameter values passed with this method. A matching record will have the same entId and eventTimeUTC values.
If there is a matching record that already exists and this flag is set to false, an error is returned, with the primary key identified in the error message.
- lastEditAt
Output. Holds the returned date/time when this record was added or last modified.
- recordsAffected
Output. If a past event was added by this method and it resulted in modifications to the previous or subsequent event, such as splitting or merging the adjacent events, then this parameter holds the number of event records affected by the transaction.
The transactions that can be executed using the Add() method are described below. In the examples provided, assume that the current time is 10:05 and the following event sequence exists: 6:00, Running; 7:00, Idle; 8:00, Downtime.
To add a new event whose start time is the current time:
Pass a null in the eventTimeUtc parameter (the updateIfExists flag can be true or false). The new event becomes the current event (in our example, starting at 10:05). No previous events for the entity are affected.
To add a new past event:
Pass the start time in UTC in the eventTimeUtc parameter (the start time must not match that of an existing event; the updateIfExists flag can be true or false).
- If the start time occurred during an event prior to the current event, then the past event during which the start time occurred is split into the existing past event and the new past event. If the new past event has the same reason as the next event, those two events are merged.
For example, if eventTimeUtc is 6:30 with the reason Machine Jam, then the updated event sequence will be: 6:00, Running; 6:30, Machine Jam; 7:00, Idle; 8:00, Downtime.
If eventTimeUtc is 6:30 with the reason Idle, then the updated event sequence will be: 6:00, Running; 6:30, Idle; 8:00, Downtime.
- If the start time occurred during the current event, then the old current event is split at the passed start time, and the new event becomes the current event. For example, if eventTimeUtc is 9:00 with the reason Machine Jam, then the updated event sequence will be: 6:00, Running; 7:00, Idle; 8:00, Downtime; 9:00, Machine Jam.
To modify an event:
Pass the start time of the event to be modified in the eventTimeUtc parameter and set the updateIfExists flag to true. The existing event's reason code, reason pending, raw reason code, and comments will be updated with the supplied values.
Observe the following input parameter rules:
- Required non-DB* parameters: Must pass a value. Cannot be empty or null.
- Optional non-DB* parameters: Either enter a value or pass a null. If passing a null and a default value has been defined, the default value will be used for the parameter.