Most MES Objects have specific events that are fired during the life cycle of the object, such as object creation New which fires every time a new instance of the object is created. Events provide the ability to add custom scripting for your application based on certain events. As an example, the Material Lot object has an event every time a new lot number is generated. You could use this to modify how lot numbers are generated.
Events can be viewed and edited from the MES Scripts > MES Object Events section of the Project Browser in Ignition Designer. Whenever an event is fired, an MESScriptEvent object is passed to the event. You can use this object to get information about the event and the object.
For more information on what events are available for which objects, please refer to the 'Object Event' section on each object help page.
There are two types of MES Object events, system events and custom events. System events are provided by default and cannot be deleted. Custom events can be created by right-clicking in the MES Events table and selecting New. Script can be added for both system and custom events in the MES Scripts > MES Object Events section of the Project Browser of the Ignition Designer to alter what happens when these events are triggered.
Custom events can be created by right-clicking on Custom Trigger Events in the MES Scripts > Custom Trigger Events section of the Project Browser and selecting Add Script. These events will only fire whenever they are called using the system.mes.executeMESEvent scripting function.
Create New Custom Trigger Event Script
Adding Scripts to System Events
Scripts can be added to change the standard behavior of system events and add functionality when custom events are triggered. This is done in the MES Scripts > MES Object Events section of the Project Browser of the Ignition Designer. Click on the event and add the script in the Script window.
System events have default behavior that occurs whenever the event fires. When you add custom script to an event, by default the custom script will execute instead of the default behavior. If you also want the default behavior to occur, add event.runDefaultHandler()
to the custom script.
Whenever an event occurs, an MESScriptEvent object is passed to the script window. The following object functions are provided to allow you to access the MES Object itself as well as execute any default behavior.
This object is used with the MESScriptEvent object to pass parameters to the MES object event and holds name value pairs where the name is a string and value is any value type of object. This object is typically used when executing user MES object events to allow passing values to the event script. The system.mes.object.parameters.create() script function can also be used to create a new instance of this object. The following object functions are available: