Start a new topic
Answered

Erroneous Business Logic behaivour

I have the following business logic collection hook. 

function onPostSave(request, response, modules) {
  var logger = modules.logger;
  if (request.body.Barcode === "None") {
    logger.info(request);
    var collectionAccess = modules.collectionAccess;
    collectionAccess.collection('user').find({ "username": modules.requestContext.getAuthenticatedUsername() }, function (err, userColl) {
      if (err) {
        logger.error('Query failed: ' + err);
      } else {
        logger.info('Query success: ' + JSON.stringify(userColl));
        logger.info(JSON.stringify(userColl));
        modules.email.send('no-reply@slyk.com',
          'michaelvowles571@gmail.com',
          'Asset Tag notification',
          'Asset tag needed for ' + userColl[0].Company +
          ', e: ' + userColl[0].email +
          ' p: ' + userColl[0].ContactNumber + '. Asset _id:' + response.body._id +
          ' Asset name: ' + response.body.AssetName +
          ' Asset OEM: ' + response.body.OEM,
          function (err, result) {
            if (err)
              logger.error(err);
            response.continue();
          });
      }
    });
  }
  response.continue();
}

 If I remove the `logger` call on the fourth line the script no longer works. However leaving it in makes it work how is this so? 


Best Answer
Michael,

The logger module gives you the ability to log data and access those logs. It is used to log a message that you can view in the console. It is just for testing purpose and not sure adding/removing it would affect code functionality or BL execution flow. For more info. please take a look at following links:

https://devcenter.kinvey.com/html5/tutorials/bl-getting-started#Logging
https://devcenter.kinvey.com/html5/reference/business-logic/reference.html#logger-module

 

Thanks,

Pranav

1 Comment

Answer
Michael,

The logger module gives you the ability to log data and access those logs. It is used to log a message that you can view in the console. It is just for testing purpose and not sure adding/removing it would affect code functionality or BL execution flow. For more info. please take a look at following links:

https://devcenter.kinvey.com/html5/tutorials/bl-getting-started#Logging
https://devcenter.kinvey.com/html5/reference/business-logic/reference.html#logger-module

 

Thanks,

Pranav

Login or Signup to post a comment