reference1 min readApplication: Platform
Journal
Methods of journal fields and journal entries, which read a record's journal history and add entries from server scripts.
A journal field, such as WorkJournal or ClientJournal on a ticket, has extra methods in server scripts. They read the field’s entries with their author and time, and add entries, without querying the journal table yourself.
Get an instance
Name the journal field on a record without calling it. The field’s methods return journal entry objects.
let latest = current.WorkJournal.activity(1)[0];
latest.author();
Journal field methods
| Method | Returns | Description | Since |
|---|---|---|---|
activity() |
Array | Every entry of the field, newest first. | 1.11 |
activity(limit) |
Array | The newest limit entries. |
1.11 |
activityAscending() |
Array | Every entry, oldest first. | 1.11 |
activityAscending(limit) |
Array | The oldest limit entries. |
1.11 |
addDelayedEntry(text) |
Journal field | Adds an entry that is created when the record is next saved. | 1.11 |
addDelayedEntry(entry, options) |
Journal field | As above. options.encoded marks the text as already encoded, and options.template names a journal template. An object as entry is stored as JSON. |
1.11 |
mapHtml(selector, callback) |
String | Calls callback(element, index) for each element of the field’s HTML that matches the CSS selector, and returns the resulting HTML. |
1.11 |
Journal entry methods
| Method | Returns | Description | Since |
|---|---|---|---|
author() |
String | The display name of the user who wrote the entry. | 1.11 |
CreatedBy() |
User record | The user who wrote the entry. createdBy() is the same. |
1.11 |
UpdatedBy() |
User record | The user who last updated the entry. updatedBy() is the same. |
1.11 |
CreatedOn() |
DateTime | When the entry was written. createdOn() is the same. |
1.11 |
UpdatedOn() |
DateTime | When the entry was last updated. updatedOn() is the same. |
1.11 |
createdOnDisplayValue() |
String | When the entry was written, formatted for the user. | 1.11 |
updatedOnDisplayValue() |
String | When the entry was last updated, formatted for the user. | 1.11 |
value() |
String | The entry as stored, in HTML. html() and entry() are the same. |
1.11 |
text() |
String | The entry as plain text, with the HTML removed. | 1.11 |
Logging an entry or converting it to JSON gives an object with author, createdOn and value.
Examples
Read the latest entry
Servicely Script
let entry = current.WorkJournal.activity(1)[0];
[entry.author(), entry.html(), entry.text()];
Response
["<user name>", "<p>Restarted the service.</p>", "Restarted the service."]
List entries oldest first
Servicely Script
current.WorkJournal
.activityAscending()
.map(function (entry) {
return entry.createdOnDisplayValue() + ": " + entry.text();
});
Response
["<date and time>: Ticket received.", "<date and time>: Restarted the service."]
Add an entry when the record is saved
current.WorkJournal.addDelayedEntry("Escalated to the second-line group.");
current.update();