
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 03:58 AM
Hi All,
I need to remove user name (ServiceNowUserName) from the below comments in journal entry in portal form. So that the end user(customer) won't see the Servicenow user name whoever replied.
For example :
JournalEntry Comment - "2023-07-24 02:14:44 - ServiceNowUserName Hi, we are working on it 2023-07-24 02:13:24 - Abdul Rahuman what happened? 2023-07-24 01:53:22 - ServiceNowUserName Can we make the Agent name invisible or change it to group name 2023-07-24 01:52:21 - Abdul Rahuman When it will be done? 2023-07-24 01:50:00 - ServiceNowUserName change it in Test instance " .
All the comments that were entered by customer and servicenow user are stored in a single journal entry field.
I need to just remove or replace it with servicenow users group name. So that the end user(customer) won't see the Servicenow user name whoever replied.
How to achieve this requirement?
Thanks,
Abdul
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 05:39 AM
Hi @Community Alums ,
Hope you are doing great.
we dont have OOB solution to built it. but if still you want you can customise it.
Here's the technical solution:
Create a new table to store the mapping of ServiceNow usernames to their respective group names. This table should have two fields: "ServiceNowUserName" and "GroupName."
Populate the table with entries for each ServiceNow user, mapping them to their respective group names.
Write a ServiceNow Business Rule that triggers whenever a new journal entry is added or updated.
In the Business Rule, extract the journal entry comments and parse them to identify the ServiceNow usernames.
For each identified username, query the reference table to get the corresponding group name.
Replace the ServiceNow username in the journal entry comments with the group name.
Save the modified journal entry back to the field.
example of code script in Business rule:
(function executeRule(current, previous /*, g*/) {
var journalEntry = current.journal_field; // Replace 'journal_field' with the actual name of the journal entry field.
// Regular expression to find ServiceNow usernames in the journal entry.
var regex = /(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s-\s)(\w+)\s/g;
var matches;
while ((matches = regex.exec(journalEntry)) !== null) {
var originalMatch = matches[0];
var userName = matches[2];
// Query the reference table to get the group name for the ServiceNow username.
var groupQuery = new GlideRecord('reference_table_name'); // Replace 'reference_table_name' with the actual name of the reference table.
groupQuery.addQuery('ServiceNowUserName', userName);
groupQuery.query();
if (groupQuery.next()) {
var groupName = groupQuery.getValue('GroupName');
// Replace the ServiceNow username with the group name in the journal entry.
journalEntry = journalEntry.replace(originalMatch, '$1' + groupName + ' ');
}
}
// Update the journal entry field with the modified comments.
current.journal_field = journalEntry; // Replace 'journal_field' with the actual name of the journal entry field.
current.update();
})(current, previous);
Regards,
Riya Verma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 05:08 AM
Hi @Community Alums ,
Unfortunately NO, there is no OOTB solution to remove it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 05:29 AM
Hi Subhadip,
1.Will it work dynamically? Because, from the form view in instance anyone from the group can comment or his superior can also comment.
2.At that time how will we pass the user name in those method and change?
3.And also, if the dynamically removing any user name is possible, will it display the end user(customer)name?
Please enlighten me.
Kindly,
Abdul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 05:39 AM
Hi @Community Alums ,
Hope you are doing great.
we dont have OOB solution to built it. but if still you want you can customise it.
Here's the technical solution:
Create a new table to store the mapping of ServiceNow usernames to their respective group names. This table should have two fields: "ServiceNowUserName" and "GroupName."
Populate the table with entries for each ServiceNow user, mapping them to their respective group names.
Write a ServiceNow Business Rule that triggers whenever a new journal entry is added or updated.
In the Business Rule, extract the journal entry comments and parse them to identify the ServiceNow usernames.
For each identified username, query the reference table to get the corresponding group name.
Replace the ServiceNow username in the journal entry comments with the group name.
Save the modified journal entry back to the field.
example of code script in Business rule:
(function executeRule(current, previous /*, g*/) {
var journalEntry = current.journal_field; // Replace 'journal_field' with the actual name of the journal entry field.
// Regular expression to find ServiceNow usernames in the journal entry.
var regex = /(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s-\s)(\w+)\s/g;
var matches;
while ((matches = regex.exec(journalEntry)) !== null) {
var originalMatch = matches[0];
var userName = matches[2];
// Query the reference table to get the group name for the ServiceNow username.
var groupQuery = new GlideRecord('reference_table_name'); // Replace 'reference_table_name' with the actual name of the reference table.
groupQuery.addQuery('ServiceNowUserName', userName);
groupQuery.query();
if (groupQuery.next()) {
var groupName = groupQuery.getValue('GroupName');
// Replace the ServiceNow username with the group name in the journal entry.
journalEntry = journalEntry.replace(originalMatch, '$1' + groupName + ' ');
}
}
// Update the journal entry field with the modified comments.
current.journal_field = journalEntry; // Replace 'journal_field' with the actual name of the journal entry field.
current.update();
})(current, previous);
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2024 11:27 AM
Hi @Riya Verma ,
i have same type of requirement , we have product quality table , if user has role "pql_admin" , so want to show "pql_admin" instead of user name in journal entry, could you please help how to achive this