{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":377,"path":"api-reference/developer-guides/prd_evt_not-dev_gd-gen_evt_pay.md","title":"Generate the payload for a new trouble ticket event","bundle":null,"doc_type":null,"release":"australia","body":"\n# Generate the payload for a new trouble ticket event\n\nWhen adding a trouble ticket event to your implementation, you must create a function that generates the required TMF-compliant payload for that event type. In addition, you must add that function to the case statement that directs the logic to this function when processing this type of event record.\n\n## Create a method that generates the payload for the new trouble ticket event\n\nIn the `TroubleTicketNotificationUtil` script include, you must add a method that constructs the required TMF-compliant payload for the new trouble ticket event and then return that payload.\n\nFor examples of methods that create payloads for the base system trouble ticket events, refer to the following methods in the [`TroubleTicketNotificationUtilOOB`](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/TroubleTicketNotifScopedAPI.md) script include:\n\n-   [generateCreateTroubleTicketEventPaylaod\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/TroubleTicketNotifScopedAPI.md)\n-   [generateCreateTroubleTicketEventPaylaodForCase\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/TroubleTicketNotifScopedAPI.md)\n-   [generateTroubleTicketAttributeChangePayload\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/TroubleTicketNotifScopedAPI.md)\n-   [generateTroubleTicketStatusChangePayload\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/TroubleTicketNotifScopedAPI.md)\n\n## Add the event to the fetchEventHandlerAndCreateTMFEvent\\(\\) switch/case logic\n\nFor the function that you created to be executed, you must add it in the `switch/case` logic within the fetchEventHandlerAndCreateTMFEvent\\(\\) method of the `EventProcessorUtil` script include. The following code snippet shows the updates necessary to add the `ResolveTroubleTicketEventForIncident` event type to this method. For details on the fetchEventHandlerAndCreateTMFEvent\\(\\) method, see [EventProcessorUtilOOB - fetchEventHandlerAndCreateTMFEvent\\(Object eventSnapshot, String eventType, String eventId\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/EventProcessorUtilOOBScopedAPI.md).\n\n```\nfetchEventHandlerAndCreateTMFEvent: function(eventSnapshot, eventType, eventId) {\n  var eventPayload;\n  switch (eventType) {\n    case Constants.EVENT_TYPES.TROUBLE_TICKET_STATUS_CHANGE:\n      eventPayload = new sn_ind_tsm_sdwan.TroubleTicketNotificationUtil().generateTroubleTicketStatusChangePayload(eventSnapshot, eventType, eventId);\n      break;\n\n    case Constants.EVENT_TYPES.TROUBLE_TICKET_CREATE:\n      eventPayload = new sn_ind_tsm_sdwan.TroubleTicketNotificationUtil().generateCreateTroubleTicketEventPaylaod(eventSnapshot, eventType, eventId);\n      break;\n\n    case Constants.EVENT_TYPES.TROUBLE_TICKET_ATTRIBUTE_CHANGE:\n      eventPayload = new sn_ind_tsm_sdwan.TroubleTicketNotificationUtil().generateTroubleTicketAttributeChangePayload(eventSnapshot, eventType, eventId);\n      break;\n\n    case Constants.EVENT_TYPES.TROUBLE_TICKET_CREATE_FOR_CASE:\n      eventPayload = new sn_ind_tsm_sdwan.TroubleTicketNotificationUtil().generateCreateTroubleTicketEventPaylaodForCase(eventSnapshot, eventType, eventId);\n      break;\n\n    // Add a new case statement for the ResolveTroubleTicketEventForIncident event type\n    case 'ResolveTroubleTicketEventForIncident':\n      eventPayload = new sn_ind_tsm_sdwan.TroubleTicketNotificationUtil().generateResolveTroubleTicketEventPyaload(eventSnapshot, eventType, eventId);\n      break;\n\n    default:\n      this._logger.debug(\"Event with id \" + eventId + \" could not find the matching payload generator\");\n      eventPayload = null;\n  }\n  return eventPayload;\n},\n```\n\n"}}