add a title in worknote & comments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2024 01:04 AM
Hello everyone,
From Washington DC. version I have regular incidents that come up concerning comments that are written several times, or even written in the name of other people. You should know on the instance on which I work there is a BR which exists and which adds a title to each comment according to business logic, of which here is an extract:
if (answer == 'true') {
current.work_notes = current.assignment_group.getDisplayValue() + "\n ****************************";
}
// If the current logged in user has an Initial Group
else if (answer != 'true' && !groupInit.nil()) {
// Fill the Incident Initial Group field
current.work_notes = groupInit.getDisplayValue() + "\n ****************************";
}
After analysis, I realized that the script in question had modified the value of the comment field but on the sys_journal_field table it created two records: 1 with the text of the comment, the other with the title. (see screenshot).
I therefore decided to change this operation, and to do the work on the client side by adding a Client script which, according to the same business logic, adds the title to the comment upon submission. It works very well except that...
if the user clicks on the post button, then the comment is added without submitting the form, therefore without launching my client script. (I tried to do another client script on the edit one, or we change but nothing to do) and as soon as I make a rule on the server side, then this stores two records on the sys_journal_field table, and therefore this amounts to what I don't want to, so as not to end up with the same incident...
Does anyone have any leads or ideas, thank you very much in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:45 AM
Because you have current.comments = prefix, and prefix does not concatenate current.comments you are adding a new comment with only the prefix. It happens at the same time and user as the posted comment is why it is showing in one activity block on the record. Try changing the last line to
current.comments = prefix + '\n' + comments;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 05:58 AM
Thanks Brad, but if i do that, it appear twice, look this screen:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 11:08 AM
I've been working on replicating this in my PDI. Journal fields are weird, then there's the activities filter, and an underlying sys_journal_field table. This is the closest I've gotten. No client script, only 1 Business Rule on the sys_journal_field table before Insert, filtering on incident and comments to only apply to this table and field
(function executeRule(current, previous /*null when async*/ ) {
var comments = current.getValue('value');
var prefix = "[code]<h4>Support ENEDIS</h4>[/code]";
current.value = prefix + '\n' + comments;
})(current, previous);
Posting a comment, or clicking Save/Submit/Update when there is a comment results in one new record on the sys_journal_field table with the header, but you'll see two entries on the incident record activities filter. I couldn't track down how to make that not happen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2024 09:08 AM
thank you very much for trying anyway, it's true that some pretty weird things are happening and I can't find any documentation on this subject, if anyone has anything interesting to suggest to me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 07:32 AM
This was gnawing at me, so I took another look. In addition to the Business Rule I proposed, if you add another BR to delete the history of the original comment being posted or saved to the incident without the header then it doesn't show it on the Activity Filter, and the sys_journal_field table still only has one record with the header.
(function executeRule(current, previous /*null when async*/) {
var histGR = new GlideRecord('sys_history_line');
histGR.addQuery('set.id', current.id);
histGR.addQuery('field', 'comments');
histGR.addQuery('type', 'audit');
histGR.query();
while (histGR.next()) {
histGR.deleteRecord();
}
})(current, previous);