# $log - Checking the Comments Log

In certain circumstances it may be useful to create in some definitions a specific field for tracking previous changes made to just one or two fields in addition to the changelog of a record in its entirety.

The $log keyword therefore enable us to emulate a typical discussion forum environment in an application built on top of the CoB platform: for each comment that is saved, a new entry is created in the comments log while the comment field is automatically cleared. This way, all the participants in the discussion will have direct access to previously published comments. This information cannot be found in the record changelog. Another advantage is that it is possible to keep a more visible record of changes in content status - next to the other record fields. An additional advantage of the $log keyword, and which is also not offered by the full changelog of the record, is that it allows a user to search for content in the log of previous comments.

# Instalation:

cob-cli customize log

# Usage:

$log(first_field,second_field)

For the keyword to work as expected three fields are required:

  • The field where we want to use the keyword, i.e. where we want to keep a log of previously published comments. In this case, the field should also include the keyword $markdown in order to indicate that it is a field containing text formatted in markdown. Another requirement is that the field should only be edited by IntegrationM. This is done by adding the keyword $editForGroup(ORG IntegrationM).
  • The field used for posting comments and that serves as the first argument to the keyword - named first_field in the code block. Thus, each saved text entry in this field will be added to the comment history field and immediately emptied.
  • The field used by the keyword as a second argument in order to track any differences - named second_field in the code block. In this case the field can be of any type: a fixed range of values - $[] -, a number - $number -, or a multiline text box - $text. It may even have no type at all.

# Examples:

In the example below, we want to display a comments log on the Previous Comments field, which is already built with the $markdown keyword. Next, we want to be able to post new comments on the New Comment field which is also built with the $markdown keyword. Finally, we want to track any differences in the state of the issue in the Proposal State field. Thus, we add the $log(New Comment,Proposal State) expression to the Previous Comments field.

At the instance level, the end result is going to be the one included in the image below:

TIP

If we want to reduce the distance between the field used posting comments and the field for tracking the logs of previously posted comments, we can use the reduceDistanceToNextField option of the keyword $style: $style[reduceDistanceToNextField].

In the video available below we can see an example of this keyword in action: