- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2023 02:02 AM
The requirement is to limit the additional comments and work notes to the latest 10 entries in the record.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2023 02:48 AM - edited ‎08-22-2023 02:56 AM
Hi @sreeshsurendran,
To limit the additional comments and work notes to the latest 10 entries in the record, you can write a Business Rule (BR) on that particular table. Choose Before Insert or Update as per your need
Follow the script and modify it as per your need -
(function executeRule(current, previous /*, g*/) {
var maxEntries = 10; // Maximum allowed entries
var workNotesCount = 0;
var additionalCommentsCount = 0;
// Calculate the number of worknotes and additional comments
var grWorkNotes = new GlideRecord("sys_journal_field");
grWorkNotes.addQuery("element_id", current.sys_id);
grWorkNotes.addQuery("element", "comments");
grWorkNotes.query();
while (grWorkNotes.next()) {
workNotesCount++;
}
var grAdditionalComments = new GlideRecord("sys_journal_field");
grAdditionalComments.addQuery("element_id", current.sys_id);
grAdditionalComments.addQuery("element", "work_notes");
grAdditionalComments.query();
while (grAdditionalComments.next()) {
additionalCommentsCount++;
}
// Check if the total entries exceed the limit
if (workNotesCount + additionalCommentsCount > maxEntries) {
gs.addErrorMessage("You can only have a maximum of " + maxEntries + " worknotes and additional comments.");
current.setAbortAction(true); // Prevent the record from being saved
}
})(current, previous);
Astik
Please mark my answer as correct if it helps you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2023 02:48 AM - edited ‎08-22-2023 02:56 AM
Hi @sreeshsurendran,
To limit the additional comments and work notes to the latest 10 entries in the record, you can write a Business Rule (BR) on that particular table. Choose Before Insert or Update as per your need
Follow the script and modify it as per your need -
(function executeRule(current, previous /*, g*/) {
var maxEntries = 10; // Maximum allowed entries
var workNotesCount = 0;
var additionalCommentsCount = 0;
// Calculate the number of worknotes and additional comments
var grWorkNotes = new GlideRecord("sys_journal_field");
grWorkNotes.addQuery("element_id", current.sys_id);
grWorkNotes.addQuery("element", "comments");
grWorkNotes.query();
while (grWorkNotes.next()) {
workNotesCount++;
}
var grAdditionalComments = new GlideRecord("sys_journal_field");
grAdditionalComments.addQuery("element_id", current.sys_id);
grAdditionalComments.addQuery("element", "work_notes");
grAdditionalComments.query();
while (grAdditionalComments.next()) {
additionalCommentsCount++;
}
// Check if the total entries exceed the limit
if (workNotesCount + additionalCommentsCount > maxEntries) {
gs.addErrorMessage("You can only have a maximum of " + maxEntries + " worknotes and additional comments.");
current.setAbortAction(true); // Prevent the record from being saved
}
})(current, previous);
Astik
Please mark my answer as correct if it helps you.