{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":3851,"path":"build-workflows/system-events/t_CreateYourOwnEvent.md","title":"Create an event","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create an event\n\nIf you do not find a suitable existing event, you can create your own.\n\n## Before you begin\n\nRole required: events\\_admin\n\n## About this task\n\nThe gs.EventQueue function works directly with the backend and therefore business rules that are called by gs.EventQueue\\(\\) are not invoked.\n\n## Procedure\n\n1.  Navigate to **All** &gt; **System Policy** &gt; **Events** &gt; **Registry**, and then select **New**.\n\n2.  On the form fill in the fields.\n\n<table id=\"table_hbv_pg3_j1c\"><thead><tr><th>\n\nField\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nEvent name\n\n</td><td>\n\nName of your new event.\n\n</td></tr><tr><td>\n\nTable\n\n</td><td>\n\nDatabase table for this event. **Note:** Only tables and database views that are in the same scope as the event appear on the listing.\n\n</td></tr><tr><td>\n\nQueue\n\n</td><td>\n\nName of the queue that the event is placed into when triggered.Use only lowercase letters, no spaces, and no special characters except underscore \\(\\_\\). For example, `my_queue`. See [Using custom queues to process events](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/scripts/useful-server-side-scripts.md).\n\n</td></tr><tr><td>\n\nPriority\n\n</td><td>\n\nOrder in which messages will be processed. Lower values have higher priority.**Note:** The com.glide.sysevent.priority.enabled system property is enabled by default. If you disable it, events processing is not done by priority.\n\n</td></tr><tr><td>\n\nCaller Access\n\n</td><td>\n\nRestricted caller access settings.-   Caller Restriction: calls to the resource must be manually approved.\n-   Caller Tracking: Calls to the resource are automatically approved.\n\n\n</td></tr><tr><td>\n\nFired by\n\n</td><td>\n\nName of the business rule that runs the event. This field is for reference only and is not used by any process. Make sure that there is enough information to locate your event again.\n\n</td></tr><tr><td>\n\nDescription\n\n</td><td>\n\nShort description of the purpose of the event.\n\n</td></tr></tbody>\n</table>3.  Click the **Business Rules** related link.\n\n4.  If you are creating an event for a base system table, select the existing event business rule for the table.\n\n    For example, select the **sc request events** business rule to create a custom Request event.\n\n5.  If you are updating an existing event business rule, add a new condition to the **Script**.\n\n    The following sample script adds a **request.commented** event with the user's Sys ID as parm1 and the user's user name for parm2.\n\n    ```\n    if (current.operation() != 'insert' && current.comments.changes()) {\n    gs.eventQueue('request.commented', current, gs.getUserID(), gs.getUserName());\n    }\n    ```\n\n6.  If you are creating an event for a custom table, create a new business rule that runs after database operations.\n\n    For example, this business rule defines several events for a custom application called Marketing Events.\n\n<table id=\"table_st1_hzs_wy\"><thead><tr><th>\n\nField\n\n</th><th>\n\nValue\n\n</th></tr></thead><tbody><tr><td>\n\nName\n\n</td><td>\n\nAttendee Events\n\n</td></tr><tr><td>\n\nTable\n\n</td><td>\n\nAttendee \\[x\\_snc\\_marketing\\_ev\\_attendee\\]\n\n</td></tr><tr><td>\n\nApplication\n\n</td><td>\n\nMarketing Events\n\n</td></tr><tr><td>\n\nAdvanced\n\n</td><td>\n\nSelected\n\n</td></tr><tr><td>\n\nWhen\n\n</td><td>\n\nafter\n\n</td></tr><tr><td>\n\nInsert\n\n</td><td>\n\nSelected\n\n</td></tr><tr><td>\n\nUpdate\n\n</td><td>\n\nSelected\n\n</td></tr><tr><td>\n\nDelete\n\n</td><td>\n\nSelected\n\n</td></tr><tr><td>\n\nScript\n\n</td><td>\n\nAdd custom script that:\n\n-   Checks for one or more conditions on the current record.\n-   Calls the gs.eventQueue\\(\\) method and specifies an event name.\n See code sample.\n\n</td></tr></tbody>\n</table>    **Note:** If you add **Filter Conditions**, **Role conditions**, or a **Condition** value, verify it runs the business rule when expected.\n\n    ```\n    (function executeRule(current, previous /*null when async*/) {\n       //This function will be automatically called when this rule is processed.\n            //Add event when attendee inserted\n            if(current.operation() == 'insert' && current.marketing_event.changes()) {\n                    gs.eventQueue('x_snc_marketing_ev.attendee.added', current,\n    current.marketing_event, current.email);\n            }\n            //Add event when marketing event changes\n            if(current.operation() == 'update' && current.marketing_event.changes()) {\n                    gs.eventQueue('x_snc_marketing_ev.attendee.deleted', previous,\n    previous.marketing_event, previous.email);\n                    gs.eventQueue('x_snc_marketing_ev.attendee.added', current,\n    current.marketing_event, current.email);\n            }\n            //Add event when attendee deleted\n            if(current.operation() == 'delete') {\n                    gs.eventQueue('x_snc_marketing_ev.attendee.deleted', current,\n                  current.marketing_event, current.email);\n    }\n    })(current, previous);\n    ```\n\n7.  Register the event.\n\n\n## What to do next\n\nCreate a script action or notification to process the event.\n\n**Parent Topic:**[Managing system events](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/system-events/managing-system-events.md)\n\n**Related topics**  \n\n\n[Register an event](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/system-events/t_RegisterAnEvent.md)\n\n[Script actions](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/system-events/r_ScriptActions.md)\n\n"}}