Running Segment with specific Date and Time 3.0
Overview
This article explains how to run a process segment using the specified date and time.
Applies To and Version Info
This feature applies to Track and Trace module and is available in version 3.8x and above.
Scripting
Execute
|
## Executes a segment and sets all properties to the given date and time
##
eqPath = 'Your Enterprise\New Site\Receiving\Milk Unloading'
seg = system.mes.createSegment('Test Date Operation', eqPath, True)
seg.setMaterial('Material In', 'Whole Milk', 'Your Enterprise\New Site\Receiving\Receiving Tanks\Whole Milk Tank 2', 'Lot 23', 200.0)
# ... set any other segment properties ...
## Executes a segment and sets all properties to the given date and time instead of the current date time
from java.util import Calendar
cal = Calendar.getInstance()
# set date to Dec 4, 2016 1:30pm
cal.set(2016, 11, 4, 13, 30, 00)## Jan=0...Dec=11
dateTime = cal.getTime()
seg.execute(dateTime)
|
Begin, Update and End
|
## Set custom date and times for a segment
## NOTE: all segment requirements are the same as if the segment is being run without setting the dates manually (in current time)
## This example has been broken up into three different scriptlets to illustrate that the begin, update and end calls may be called
## from different scripts.
##
#######################################################################################
eqPath = 'Your Enterprise\New Site\Receiving\Milk Unloading'
seg = system.mes.createSegment('Test Date Operation', eqPath, True)
seg.setMaterial('Material In', 'Whole Milk', 'Your Enterprise\New Site\Receiving\Receiving Tanks\Whole Milk Tank 2', 'Lot 23', 200.0)
# ... must set any other required segment properties before begin is called ...
## Begins the segment and sets all properties to the given date and time instead of the current date time
from java.util import Calendar
cal = Calendar.getInstance()
# set date to Dec 4, 2016 1:35pm
cal.set(2016, 11, 4, 13, 35, 00)## Jan=0...Dec=11
dateTime = cal.getTime()
seg = seg.begin(dateTime)
#############################################################################
eqPath = 'Your Enterprise\New Site\Receiving\Milk Unloading'
currSegList = system.mes.getCurrentSegments(eqPath)
if currSegList.size() >= 0:
currSeg = currSegList.get(0).getMESObject()
currSeg.setMaterial('Material In', 'Whole Milk', 'Your Enterprise\New Site\Receiving\Receiving Tanks\Whole Milk Tank 1', 'Lot 23A', 150.0)
# ... must set any other required segment properties before update is called ...
## Updates the segment and sets any new properties to the given date and time instead of the current date time
from java.util import Calendar
cal = Calendar.getInstance()
# set date to Dec 4, 2016 1:40pm
cal.set(2016, 11, 4, 13, 40, 00)## Jan=0...Dec=11
dateTime = cal.getTime()
currSeg = currSeg.update(dateTime)
#############################################################################
eqPath = 'Your Enterprise\New Site\Receiving\Milk Unloading'
currSegList = system.mes.getCurrentSegments(eqPath)
if currSegList.size() >= 0:
currSeg = currSegList.get(0).getMESObject()
## Ends the segment and sets any active properties to the given date and time instead of the current date time
from java.util import Calendar
cal = Calendar.getInstance()
# set date to Dec 4, 2016 1:45pm
cal.set(2016, 11, 4, 13, 45, 00)## Jan=0...Dec=11
dateTime = cal.getTime()
currSeg.end(dateTime)
|