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

Multiple Onclick Functions - UI Action

Andrew Parkes
Tera Expert

Hi all,

 

Is it possible to have multiple onClick functions in a UI action? 

E.g:

resolveIncident(); copyAttachments()
1 ACCEPTED SOLUTION

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

View solution in original post

11 REPLIES 11

Is the purpose of this to both resolve the incident and also generate your email_client_attachemnts UI page? So once the UI page is finished with and destroyed, the second resolveIncident should be invoked?

Hi Kieran - exactly that! any ideas??

As part of your UI Page you'll need to call your resolveIncident() function. As an example of an OOB UI Page that does this, have a look at the Cancel Change UI Action on the change_request table.

 

As you can see from the below, the UI Page change_confirm_cancel is loaded and there is also a moveToCancel function.

find_real_file.png

 

Within the UI Page client script, you can see this function being called as part of the button onClick action.

find_real_file.png

 

So in your client script for your custom UI Page, you just need to call the function.

Thanks Kieran,

 

I've just tried to configure the UI Page, calling the resolve functions before the dialog window is destroyed (and after) without any joy. I'm certain im doing something wrong! would you mind giving me a hand please?

UI Action (Resolve):

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
}
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();
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
	serverResolve();

function serverResolve(){
	current.incident_state = IncidentState.RESOLVED;
	current.state = IncidentState.RESOLVED;
	current.resolved_by = gs.getUserID();
	current.update();
}

UI Page (Email_Client_Attachments):

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
	
	GlideDialogWindow.get().destroy(); //to automatically close the window
}


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
}
if (typeof window == 'undefined')
	serverResolve();

function serverResolve(){
	current.incident_state = IncidentState.RESOLVED;
	current.state = IncidentState.RESOLVED;
	current.resolved_by = gs.getUserID();
	current.update();
}
function myFunctionCancel()
{
	GlideDialogWindow.get().destroy();
}

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