AddUtil Method
- Last UpdatedNov 06, 2025
- 4 minute read
The AddUtil() method is maintained for compatibility with MES versions prior to 6.0. For new projects, this method should not be used. Instead, use the Add() and AddEvent() methods in the UtilHistory class.
The AddUtil() method updates an existing record in the Util_History table if one exists with the same eventTime and entId as those passed in the method call. If such a record does not exist, the method adds a new utilization event to the Util_History table.
'Declaration
Public Shared Sub AddUtil( _
ByVal sessionId As Integer, _
ByVal eventTime As Date, _
ByVal entId As Integer, _
ByVal shiftId As Integer, _
ByVal shiftStart As Date, _
ByVal stateCode As Integer, _
ByVal reasonCode As Integer, _
ByVal rawReasonCode As String, _
ByVal reasonPending As Boolean, _
ByVal failure As Boolean, _
ByVal duration As Integer, _
ByVal comments 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 lastEditComment As String, _
ByRef logId As Integer, _
ByRef lastEditAt As Date _
)
'Usage
Dim sessionId As Integer
Dim eventTime As Date
Dim entId As Integer
Dim shiftId As Integer
Dim shiftStart As Date
Dim stateCode As Integer
Dim reasonCode As Integer
Dim rawReasonCode As String
Dim reasonPending As Boolean
Dim failure As Boolean
Dim duration As Integer
Dim comments 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 lastEditComment As String
Dim logId As Integer
Dim lastEditAt As Date
UtilLog.AddUtil(sessionId, eventTime, entId, shiftId, shiftStart, stateCode, reasonCode, rawReasonCode, reasonPending, failure, duration, comments, spare1, spare2, spare3, spare4, category1, category2, category3, category4, lastEditComment, logId, lastEditAt)
public static void AddUtil(
int sessionId,
DateTime eventTime,
int entId,
int shiftId,
DateTime shiftStart,
int stateCode,
int reasonCode,
string rawReasonCode,
bool reasonPending,
bool failure,
int duration,
string comments,
string spare1,
string spare2,
string spare3,
string spare4,
string category1,
string category2,
string category3,
string category4,
string lastEditComment,
out int logId,
out DateTime lastEditAt
)
Parameters
- sessionId
- Required. Holds the session ID and thus the user who is making this method call.
- eventTime
- Required. Holds the date/time for the start of the utilization event. Cannot be more than 2 minutes in the future; otherwise, an error will be returned.
- entId
- Required. Holds the ID of the entity to which this utilization event is being added.
- shiftId
Required. Holds the ID of the shift during which the utilization event took place.
For MES version 6.0 and later, this parameter is ignored.
- shiftStart
Required. Holds the date/time for the start of the shift during which the utilization event took place.
For MES version 6.0 and later, this parameter is ignored.
- stateCode
- Optional. Holds the code identifying the utilization state for the entity.
- reasonCode
- Required. Holds the code identifying the reason for the utilization event.
- rawReasonCode
- Optional. Holds the code identifying the raw reason used to determine the utilization reason.
- reasonPending
- Required. Holds a flag that indicates whether or not the reason needs to be finalized.
- failure
- Required. Holds a flag that indicates whether or not to count the event as a failure.
- duration
- Required. Holds the number of seconds the event lasted. Cannot be 0; otherwise, an error will be returned.
- comments
- Optional. Holds text to describe the event.
- 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 string which can be used to categorize the event.
- category2
- Optional. Holds a string which can be used to categorize the event.
- category3
- Optional. Holds a string which can be used to categorize the event.
- category4
- Optional. Holds a string which can be used to categorize the event.
- lastEditComment
- Optional. Holds comments that describe why this record is being added.
- logId
Output. Holds the returned ID of the new event.
- lastEditAt
Output. Holds the returned date/time when this record was added. The lastEditAt parameter is used by other methods that modify or delete this record for optimistic concurrency control.