- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2020 08:13 AM
Hi all,
Is it possible to have multiple onClick functions in a UI action?
E.g:
resolveIncident(); copyAttachments()
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2020 04:58 AM
Hi,
You don't need to add the function into the UI Client Script, you just need to call it.
function myFunctionSubmit(){
var x = $$('.attachment_checkbox[value=true]'); //array of the checkbox elements
if(x.length == 0)
{
alert("Please select an attachment");
return false;
}
else if (x.length > 0)
{
var list_of_attchs_ids = '';
var attch_name = '';
for (var j=0; j< x.length; j++) {
//get the sys_id of the attachment from the checkbox element name
attch_name = x[j].name.split(':');
if (list_of_attchs_ids=='')
list_of_attchs_ids = attch_name[1];
else
list_of_attchs_ids = list_of_attchs_ids + ','+ attch_name[1];
}
var ajax = new GlideAjax("getAttachmentLists");
ajax.addParam("sysparm_name","updateAttachmentList");
ajax.addParam("sysparm_attachmentsysid",list_of_attchs_ids);
ajax.getXMLWait();
}
var ticket_id = g_form.getUniqueValue();
var table_name = g_form.getTableName();
var newURL = 'email_client.do?sysparm_table=' + table_name + '&sysparm_sys_id='+ ticket_id +'&sysparm_target=' + table_name + '&sys_target=' + table_name + '&sys_uniqueValue=' + ticket_id +
'&sys_row=0&sysparm_encoded_record='; //build the URL of the email client window
//alert(newURL);
popupOpenEmailClient(newURL); //opens the email client
resolveIncident();
GlideDialogWindow.get().destroy(); //to automatically close the window
}
function myFunctionCancel()
{
GlideDialogWindow.get().destroy();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2020 08:23 AM
You can just call the function within the script from the original function. i.e. your onClick is 'resolveIncident();' and within the resolveIncident function it can call your copyAttachments() function if that's what you're asking.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2020 08:24 AM
The onclick just invokes the referenced client side function. You don't need to have multiple, you can instead just invoked those additional functions from the onclick
i.e. You'd just call the onClick which will inturn call copyAttachments from within it.
function onClick(){
//Do something
CopyAttachments();
}
function CopyAttachments() {
//Do something
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2020 08:24 AM
Hi,
I guess you can have one function, and based on whatever conditions you can call multiple functiosn from there.
But entry point will be 1.
For EG:
Primary function: primaryFunc();
function primaryFunc(){
if(g_form.getValue('state')==1)
copyAttachments();
else
resolveIncident();
}
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2020 08:32 AM
Thanks all,
Sorry, i should've provided more information.
The first function which should be called is "copyAttachments()" which opens a dialog box where attachments can be selected to be copied to the email client, works on it's own UI Action.
The second being resolve INC which essentially resolves the incident as normal.
I've added the functions into the script, see below, but it doesn't seem to be bringing up the dialog.
function copyAttachments(){
var gdw = new GlideDialogWindow('Email_Client_Attachments');
gdw.setTitle('Please select the Attachments to Copy to Email Client');
gdw.setSize(450,300);
gdw.setPreference('sysparm_sys_id', g_form.getUniqueValue()); // Our task record ID
gdw.render();
}
function resolveIncident(){
//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
g_form.setValue('incident_state', 6);
g_form.setValue('state', 6);
g_form.setValue('resolved_by', g_user.userID);
gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}