{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":3844,"path":"build-workflows/system-events/r_BuildAScript.md","title":"The incident events business rule","bundle":null,"doc_type":null,"release":"australia","body":"\n# The incident events business rule\n\nThe incident events business rule comes with the system and defines a number of events that can be triggered by different actions in the Incident table.\n\nThis business rule defines several events, three of which are triggered after a record in the Incident table is inserted or updated. The first script is:\n\n```\nif (current.operation() != 'insert' && current.comments.changes()) {\ngs.eventQueue(\"incident.commented\", current, gs.getUserID(), gs.getUserName());\n}\n```\n\nThe condition in this script requires that a change be made to the **Comments** field in an existing \\(not inserted\\) incident record. If this condition is true, then the platform adds the `incident.commented` event to the event queue.\n\nThe second condition requires that a record be inserted before the event is added to the queue.\n\n```\nif (current.operation() =='insert') {\n```\n\nThe third condition is true whenever the incident record is updated \\(including updates to the **Comments** field, as specified by the first script\\).\n\n```\nif (current.operation() == 'update')\n```\n\nThe then part of each script, the gs.eventQueue function, adds the event to the event queue. This statement uses the following syntax, set off with braces:\n\n```\ngs.eventQueue(\"incident.updated\", current, gs.getUserID(), gs.getUserName());\n```\n\nThe gs.eventQueue function takes the following parameters:\n\n|Field|Input Value|\n|-----|-----------|\n|Name|The name of the event triggered, set in quotation marks.|\n|Record|The record referenced when the condition in the script evaluates to true. Usually this is expressed as current, meaning the current record the business rule is working on. If the business rule is being triggered as part of a scheduled job, use a GlideRecord argument in its place.|\n|Parm 1|An optional parameter you can use to pass system or record information with the event. For example, the GlideSystem API call gs.getUserID\\(\\) passes the Sys ID of the user who acted on the current record as a string value. Other scripts can reference this string value as parm1 using the format `${event.parm1}`.|\n|Parm 2|An optional parameter you can use to pass system or record information with the event. For example, the GlideSystem API call gs.getUserName\\(\\) passes the user name of the user who acted on the current record. Other scripts can reference this string values as parm2 using the format `${event.parm2}`.|\n\n**Note:** The gs.EventQueue function works directly with the backend and therefore business rules that are called by gs.EventQueue\\(\\) are not invoked.\n\n**Parent Topic:**[System events reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/system-events/system-events-reference.md)\n\n"}}