CHAPTER 6

Step 6: Create Event Objects

In order to update data using the Core Library, it is necessary to create and send JSON formatted event payload objects. Since the structure and content of event objects varies between event types, a createEvent() method is available which creates a JSON payload object.

The createEvent() method takes an event name as an argument. The list of available event can be found in the readme file that accompanies the configuration file.

The resulting payload object will contain placeholders that can be modified as required. Examples of placeholders are DELETE_STRING and DELETE_INTEGER.

An excerpt of a payload object is shown below.

"transform": {
    "worker": {
     "person": {
       "legalName": {
          "givenName": "DELETE_STRING",
         "middleName": "DELETE_STRING",
          "familyName1": "DELETE_STRING",
         "familyName2": "DELETE_STRING",
         "formattedName": "DELETE_STRING",

The resulting JSON object can be updated as required and then used with the saveEvent() method. The JSON object will also contain an ‘eventID’ attribute that should not be removed or modified as it is used by the Core Library to map to the use of createEvent() is not required, though it does guarantee that the resulting payload object is correctly structured.

Note that it is not necessary to remove the placeholder entries prior to calling the saveEvent() method, as they will be stripped out when setting the data.

The code example below shows how to create a legal name change event payload object after the Consumer Application Instance has been created.

app.createEvent( 
    {methodName: ‘events.hr.v1.worker.legal.name.change’},
    (err, eventPayload) => {
        console.log(‘Received: ', err, eventPayload);
    }
);