How to add comments to tickets when UI action is clicked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 12:44 PM
For UI Actions, how would I add to the script to create a ticket comment whenever the button is used (i.e. if an analyst clicks the Send to Callback button in the ticket, put a note in the comments saying something like "Send to Callback button clicked by [analyst].").
I know to use gs.getUserDisplayName(), but I’m unsure of how to add a comment to the current ticket.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 12:48 PM
Hi,
If the UI Action is server side only, you can simply use:
current.comments = "Text here";
current.update();
action.setRedirectURL(current); //to save and stay on page
Otherwise, if it's client side, then you can use:
g_form.setValue('comments', "Text here");
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 01:08 PM
Hello Allen, thank you for your response. Looks like I am working with a majority of client UI Action scripts. I tried the below script, but it did not work.
function emailEscalationPopup() {
var sysid = g_form.getUniqueValue('sys_id');
var tableName = g_form.getTableName();
var altID = g_form.getValue('correlation_id');
var number = g_form.getValue('number');
var gdw = new GlideModal('email_plus');
//title of the pop up window
gdw.setTitle('Escalation Email');
//setPreference passes through any needed values
gdw.setPreference('sysparm_ritm', sysid);
gdw.setPreference('sysparm_tableName', tableName);
gdw.setPreference('sysparm_altID', altID);
gdw.setPreference('sysparm_number', number);
//Open the dialog window
gdw.render();
}
//Creates comment with username when UI Action is clicked
var userName = gs.getUserDisplayName();
g_form.setValue('comments', "HCHB Escalation button clicked by " + userName);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2021 06:58 AM
Hi,
You have a few things going on that you didn't specify in your original post. Such as the client element of this and also that you're calling a modal. So without this question going down a rabbit hole due to all this, you can post comments using client script with a UI Action that looks like so:
Script section:
function postComment() {
var userName = g_user.userName;
g_form.setValue('comments', "This is a test submitted by " + userName);
g_form.submit();
}
This is an example...you will need to adjust your script and UI Action, but you can use the above as a reference.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!