{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":759,"path":"api-reference/server-api-reference/EventProcessorUtilOOBScopedAPI.md","title":"EventProcessorUtilOOB - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# EventProcessorUtilOOB- Scoped\n\nThe EventProcessorUtilOOB script include provides methods to construct and publish events on the configured message broker.\n\nIf you want to change the default functionality of this script include, you need to override these methods in the `EventProcessorUtil` script include. You must have the admin role to modify this script include.\n\nThis script include runs in the `sn_api_notif_mgmt` namespace.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## EventProcessorUtilOOB - constructandPublishEvent\\(Object inboundEventPayloadRecord, String eventId\\)\n\nConstructs a TMF688 compliant payload based on the passed information and publishes the event to the configured publishing platform.\n\nThe default publishing platform is defined in the sn\\_api\\_notif\\_mgmt.publisher\\_message\\_bus\\_config system property.\n\n**Note:** This method is a core utility method of queue management. You should not need to override this method unless you plan on redesigning the underlying notification framework.\n\n|Name|Type|Description|\n|----|----|-----------|\n|inboundEventPayloadRecord|Object|Information associated with the event. The format of this payload is dependent on the event type. In the base implementation, this is the glide record data of the associated event in JSON format.|\n|eventId|String|Unique ID of the event to publish such as a GUID.|\n\n|Type|Description|\n|----|-----------|\n|tmfEventPayload|TMF688-compliant event payload created for the event. For a description of the default format of this event payload, refer to the [TMF688 Event Management API User Guide](https://www.tmforum.org/resources/standard/tmf688-event-management-api-user-guide-v4-0-0/).|\n\nThe following code example shows how to call this method.\n\n```\nprocessIndividualEventRecord: function(inboundQueueGr, node_id) {\n  var isError = false;\n  var errorMessage;\n  try {\n    new EventProcessorUtil().constructandPublishEvent(JSON.parse(inboundQueueGr.getValue('payload')), inboundQueueGr.getValue('record_id'));\n  } catch (ex) {\n    this._logger.logErr(\"Event processing failed \" + ex);\n    isError = true;\n    errorMessage = JSON.stringify(ex);\n  }\n\n  // Update the inbound queue record based on processing\n  var inboundQueueObj = new sn_tmt_core.BaseObject();\n  if (isError == true) {\n    inboundQueueObj.setValue('state', sn_tmt_core.Constants.INBOUND_QUEUE_STATE.ERROR);\n    inboundQueueObj.setValue('error_message', errorMessage);\n  } else {\n    inboundQueueObj.setValue('state', sn_tmt_core.Constants.INBOUND_QUEUE_STATE.COMPLETED);\n  }\n    var inboundQueue = new sn_tmt_core.InboundQueue(inboundQueueGr, false);\n    inboundQueue.updateInboundQueueRecord(inboundQueueObj);\n},\n```\n\n## EventProcessorUtilOOB - fetchEventHandlerAndCreateTMFEvent\\(Object eventSnapshot, String eventType, String eventId\\)\n\nConverts the passed raw event object into a TMF-compliant event object by invoking a payload generator based on the event type.\n\nYou will need to override this method if your implementation does any of the following:\n\n-   Modifies the existing event handling.\n-   Adds a new event type. You must add the event type and its associated payload generator.\n-   Adds a new object in the Producer Event Notification Framework.\n\nYou may also need to override the methods within the `TroubleTicketNotificationUtil` script include to add attributes to the returned TMF-compliant payload or modify the default handling of the payload.\n\nFor additional information, see [Configure trouble ticket notifications using the Producer Event Notification Framework](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/developer-guides/prd_evt_not-dev_gd-cfg_trbl_tkt_not.md).\n\n<table id=\"table_bq5_4nz_5zb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\neventSnapshot\n\n</td><td>\n\nObject\n\n</td><td>\n\nRaw data to transform into a TMF-compliant object.You can obtain this object from the payload field of the Inbound Queue \\[sn\\_tmt\\_core\\_inbound\\_queue\\] table. Inbound queue records are created by business rules, such as Trouble Ticket Attribute Change Event, which is associated with the Incident \\[incident\\] table.\n\nThe format of the event snapshot is defined by the business rule that originally pushed the event into the inbound queue.\n\n</td></tr><tr><td>\n\neventType\n\n</td><td>\n\nString\n\n</td><td>\n\nEvent type. This value specifies the type of event data that is passed in the **eventSnapshot** payload. The passed payload is processed based on this event type. The event type is stamped on the inbound queue record by the associated business rule on the associated table. Each event type has its own event payload structure. For example:```\n{\n  \"eventId\":\"dc2003c2c3bb3550054e20bdc0013136\",\n  \"@type\":\"Troubleticket\",\n  \"eventType\":\"TroubleTicketCreateEvent\",\n  \"event\":{\n    \"troubleTicket\":{\n      \"short_description\":\"Test payload\",\n      \"severity\":3,\n      \"ticketType\":\"incident\"\n    }\n  }\n}\n```\n\nDefault values for trouble ticket event types are defined in the **EVENT\\_TYPES** parameter in the `sn_api_notif_mgmt.Constants` script include.\n\n</td></tr><tr><td>\n\neventId\n\n</td><td>\n\nString\n\n</td><td>\n\nUnique identifier of the event to convert.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|tmfEventPayload|Event payload in TMF-compliant format. To see the transformation process of the passed **eventSnapshot** object to the TMF-compliant payload, review the code in the `TroubleTicketNotificationUtilOOB` script include.|\n\nThe following code example shows how to call this method.\n\n```\nconstructandPublishEvent: function(inboundEventPayloadRecord, eventId) {\n  if (gs.nil(inboundEventPayloadRecord)) return;\n  var tmfEventPayload = this.fetchEventHandlerAndCreateTMFEvent(inboundEventPayloadRecord.eventSnapshot, inboundEventPayloadRecord.eventType, eventId);\n\n  this._logger.debug(\"Event payload generated for the event id \" + eventId + \" is \" + JSON.stringify(tmfEventPayload));\n\n  if (gs.getProperty(Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION) == Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION_VALUES.OPEN_MESSAGE_BUS) {\n    // Publish event in custom message bus\n      this.publishEventToOpenMessageBus(tmfEventPayload);\n\n  } else if (gs.getProperty(Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION) == Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION_VALUES.HERMES) {\n    // Publish event in hermes kafka\n    try {\n      this.publishMessageToHermesKafka(tmfEventPayload);\n    } catch (ex) {\n      this._logger.logErr(\"Publishing message to Hermes Kafka Failed, error is: \" + ex);\n    }\n  } else if (gs.getProperty(Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION) == Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION_VALUES.BOTH_MESSAGE_BUS_CONFIGURATIONS) {\n    // Publish event in both custom message bus and hermes kafka\n    this.publishEventToOpenMessageBus(tmfEventPayload);\n    try {\n      this.publishMessageToHermesKafka(tmfEventPayload);\n    } catch (ex) {\n      this._logger.logErr(\"Publishing message to Hermes Kafka Failed, error is: \" + ex);\n    }\n  }\n  return tmfEventPayload;\n},\n```\n\nThe following code example shows the switch case statements used by this method to determine how to transform the passed event payload based on the **eventType** parameter. If you add other event types to your implementation, you must override this method and include the processing for the new event type.\n\n```\nfetchEventHandlerAndCreateTMFEvent: function(eventSnapshot, eventType, eventId) {\nvar eventPayload;\nswitch (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  // New event type in trouble ticket\n  case ‘troubleTicketPriorityChange’\n    eventPayload = new sn_ind_tsm_sdwan.TroubleTicketNotificationUtil().generateTroubleTicketAttributeChangePayload(eventSnapshot, eventType, eventId);\n    break;\n\n  // New event type of object other than trouble ticket\n  case ‘domainOrderStatusChange’\n    eventPayload = new sn_ind_tmt_orm().domainOrderNotification().generatedomainOrderStatusChangePayoad(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  }\nreturn eventPayload;\n},\n```\n\n## EventProcessorUtilOOB - publishMessageToHermesKafka\\(Object tmfEventPayload\\)\n\nInstantiates the HermesEventPublisher class and publishes the passed event payload to the Hermes Kafka message broker.\n\n|Name|Type|Description|\n|----|----|-----------|\n|tmfEventPayload|Object|TMF688-compliant event payload created for the event. For a description of the default format of this event payload, refer to the [TMF688 Event Management API User Guide](https://www.tmforum.org/resources/standard/tmf688-event-management-api-user-guide-v4-0-0/).|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this method.\n\n```\nconstructandPublishEvent: function(inboundEventPayloadRecord, eventId) {\n  if (gs.nil(inboundEventPayloadRecord)) return;\n  var tmfEventPayload = this.fetchEventHandlerAndCreateTMFEvent(inboundEventPayloadRecord.eventSnapshot, inboundEventPayloadRecord.eventType, eventId);\n\n  this._logger.debug(\"Event payload generated for the event id \" + eventId + \" is \" + JSON.stringify(tmfEventPayload));\n\n  if (gs.getProperty(Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION) == Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION_VALUES.OPEN_MESSAGE_BUS) {\n    // Publish event in open message bus\n    this.publishEventToOpenMessageBus(tmfEventPayload);\n\n  } else if (gs.getProperty(Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION) == Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION_VALUES.HERMES) {\n    // Publish event in Hermes Kafka\n    try {\n      this.publishMessageToHermesKafka(tmfEventPayload);\n    } catch (ex) {\n        this._logger.logErr(\"Publishing message to Hermes Kafka Failed, error is: \" + ex);\n    }\n  } else if (gs.getProperty(Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION) == Constants.EVENT_PUBLISH_MESSAGE_BUS_CONFIGURATION_VALUES.BOTH_MESSAGE_BUS_CONFIGURATIONS) {\n    // Publish event in both custom message bus and Hermes Kafka\n    this.publishEventToOpenMessageBus(tmfEventPayload);\n    try {\n      this.publishMessageToHermesKafka(tmfEventPayload);\n    } catch (ex) {\n      this._logger.logErr(\"Publishing message to Hermes Kafka Failed, error is: \" + ex);\n    }\n  }\n  return tmfEventPayload;\n},\n```\n\n"}}