Extract user details from case comment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 10:56 PM
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 08:43 AM - edited 05-01-2025 08:44 AM
Hi @SiluniP
I can suggest 2 ways to get the user details from comment. Once you received comments added to the record from the above script.
First Example:
You can extract the user name from the comment. Then use the name to query the sys_user table to get the email of the user who added that comment.
Example of the comment retrieved from the incident record:
"Script: 2025-05-01 07:20:30 - Abel Tuter (Architect) (Work notes) This is test comment"
You can refer below code to get the user name from the comment:
var retrivedComment = "Script: 2025-05-01 07:20:30 - Abel Tuter (Architect) (Work notes) This is test comment";
var inputString = retrivedComment;
// Split the string by the hyphen
var parts = inputString.split('-');
// Check if there are at least three parts
if (parts.length >= 4) {
// Get the text after the third hyphen
var textAfterThirdHyphen = parts[3].trim();
// Find the index of "(Work notes)"
var workNotesIndex = textAfterThirdHyphen.indexOf("(Work notes)");
// Extract the text before "(Work notes)"
var extractedText = workNotesIndex !== -1 ? textAfterThirdHyphen.substring(0, workNotesIndex).trim() : textAfterThirdHyphen.trim();
gs.info(extractedText); // Output: Abel Tuter (Architect)
} else {
gs.info("Text not found");
}
Once the output received query user table with output received (User Name) from the above script to get user email.
Second Example:
You can extract the user name and comment from the record. Then use both name and comment to query "sys_journal_field" table where all the comment will be stored. after query when record found use createdby field to get the email id.
I will recommend the First example. Because in Second Example the table use to make query will have so many records which may impact the instance performance.
If I am able to help you with your question, Please click the Thumb Icon and mark as Correct.
Regards,
Pushkar