Add automatic comment to tickets as Assigned To
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 08:20 AM
Hi,
I have a requirement where I am fetching a message from one table and I have to add that message as a comment on a ticket on another table. This should run when someone updates the ticket. Now I created a BR but when that BR is executed it adds the custom message comment with the same name of whoever updates the ticket instead of assigned to user. So, if requester is updating the ticket that triggers the BR and the comment is also added with requester name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 08:39 AM
Hi @Himanshu Mathur ,
You can modify your business rule to retrieve the assigned user and use their name when adding the comment. Here's an example of how you can achieve this:
(function executeRule(current, previous) {
// Get the assigned user information
var assignedUser = new GlideRecord('sys_user');
if (assignedUser.get(current.assigned_to)) {
var assignedUserName = assignedUser.name;
// Add a comment with the assigned user's name
var comment = 'The ticket has been updated. Assigned to: ' + assignedUserName;
current.comments = comment;
}
})(current, previous);
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2023 08:58 AM
Hi @Himanshu Mathur ,
Hope you are doing great.
To ensure that the comment is added with the name of the assigned user instead of the updater, you can modify the BR by including the logic to fetch the assigned user and associate the comment with their name. To fetch the assigned user and use their name for the comment, Try using below code for reference :
// Get the current ticket record
var ticket = current;
var assignedUser = new GlideRecord('sys_user');
assignedUser.get(ticket.assigned_to);
// Create the comment using the assigned user's name
var comment = "Custom message added by: " + assignedUser.name;
var gr = new GlideRecord('u_ticket_comments');
gr.initialize();
gr.setValue('ticket', ticket.sys_id);
gr.setValue('comment', comment);
gr.insert();
Regards,
Riya Verma