Add Case field value as an Additional Comment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2024 08:17 AM
Is it possible to have a value entered in a field on a Case, to be added to Activities as an Additional Comment instead of a Work Note? And, for it to only apply to a specific Case view?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2024 09:57 AM
Hi @MStritt,
Yes, it is possible to customize how values are entered in a field on a Case and then added to Activities as an Additional Comment instead of a Work Note, and for this to apply only to a specific Case view in ServiceNow. Here is an outline of how you can achieve this:
Step 1: Create a Custom Field
1. Navigate to the Case table in ServiceNow.
2. Add a new field to the Case form (e.g., 'u_custom_comment')
Step 2: Create a Business Rule
When: 'before' or `after` (depending on when you want the rule to run)
Script:
(function executeRule(current, previous /*null when async*/) {
if (current.u_custom_comment) {
// Create a new journal entry in Additional Comments
var journalEntry = new GlideRecord('sys_journal_field');
journalEntry.initialize();
journalEntry.element_id = current.sys_id;
journalEntry.name = 'comments';
journalEntry.value = current.u_custom_comment;
journalEntry.insert();
}
})(current, previous);
Step 3: Filter the View
1. Navigate to System UI > UI Policies or Client Scripts.
2. Create a new UI Policy or Client Script.
3. Configure it to apply only to the specific view you want.
For a Client Script:
Type:'onLoad'
Script:
if (g_form.getViewName() == 'specific_view_name') {
// Your logic here
}
By following these steps, you can customize the Case form to add values entered in a specific field to the Activities as Additional Comments instead of Work Notes, and ensure this customization only applies to a specific Case view.
Thank you, Please mark helpful, if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2024 10:02 AM
Thanks Yashsvi!
Do I need to create the Business Rule AND a UI Policy or Client Script (if I want it to apply to a specific view)? What would be the '// Your logic here' be for the UI Policy or Client Script? Same as used for the Business Rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2024 10:11 AM
Yashsvi,
The value of the field is close_notes. Also, is it possible to preface the comment with additional text? For example, when an agent adds a comment in close_notes (text field), we'd like the following before it.
Example:
Value in close_notes is 'Fixed the issue after adding additional script'. We'd like to add 'This Case has been closed with the following solution provided:' before it. So it would display in Additional comments as:
'This Case has been closed with the following solution provided: Fixed the issue after adding additional script.'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2024 10:22 AM
Hi @MStritt ,
You can write a Business rule for a particular view as well.
use this code snippet to apply the logic for specific view only.
if (g_form.getViewName() == 'your_view_name') {
// Write your logic here
}