Step 7: Saving Data with the ADP Core Library

To save data it is necessary to create an event payload object, update it’s contents, and then save it. The saveEvent() method takes an event object as an argument and sends it to the appropriate ADP endpoint.

Prior to sending the event, the event payload object will be validated prior to sending the event. If any errors are found during validation they will be returned as an array of error messages. An excerpt of a validation failure object is shown below.

[ ValidationException {
    message: 'Value is not optional and must be set.',
    pathToError: 'events/0/data/transform/worker/person/legalName/givenName',
    description: 'Non-optional value',
    context: '' },
  ValidationException {
    message: 'Value is not within acceptable range between 1 and 64',
    pathToError: 'events/0/data/transform/worker/person/legalName/givenName',
    description: 'Value length',
    context: '' 
} ]

After processing the event, a response data will be returned that contains a JSON object with the results of the call. The structure of the JSON object is the same as that returned by a normal REST API call to post an event.

The following code example below shows how to update the last name for a worker, after the Consumer Application Instance and legal name change payload has been created.[0].data.eventContext.worker.associateOID = ‘FFEEDDAABBCC0011’;[0].data.transform.worker.person.legalName.givenName = 'Thomas';[0].data.transform.worker.person.legalName.familyName1 = 'Anderson';

app.saveEvent( payload, (err, response) => {
    console.log( “Received: ”, err, response );