The CreatorCon Call for Content is officially open! Get started here.

How to add comments to tickets when UI action is clicked

MrBun256
Tera Contributor

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.  

3 REPLIES 3

Allen Andreas
Administrator
Administrator

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

find_real_file.png

find_real_file.png

find_real_file.png

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!

MrBun256
Tera Contributor

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);

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:

find_real_file.png

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!