What is the equivalent of gsft Submit in list view?

reginabautista
Kilo Sage

Hi guys,

I am trying to update records from a list view using a UI action (List context menu=true) and would like to call gsftSubmit function, however as I am in a list view, the g_form.getFormElement() is unavailable in this context.

gsftSubmit(null, g_form.getFormElement(), 'reopen_incident'); //MUST call the 'Action name' set in this UI Action

Would you know what's the alternative?

4 REPLIES 4

Harsh Vardhan
Giga Patron

have you tried with



g_list.action('[sys_id of the reopen_incident UI action]', 'reopen_incident');  


Hi harsh thanks for the repl. I ended up re-doing my code and just stick to using the current object. All's good now. Thanks


could you tell how you used current object

 

Harsh:

This was very helpful.  I was able to make a UI action that had client and server code that worked in list and form view.  

How did you discover of this method?   

 

In case anyone needs to do something similar here is my code:

Started here... https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

function confirmRetire() {
	
	var userConfirmed = false;
	
	try {
		//try to get the items the user checked,
		//if the object is undefined that means we are on the form
		var checkedItems = g_list.getChecked();
		
		userConfirmed = confirm('Are you sure you want to retire ' + checkedItems.split(',').length + ' assets?');
		
		if (userConfirmed) {
			
			g_list.action('106d12e6dbe46f00c8df80c74b9619c3', 'retire_asset');   
			
		} else {
			
			return false;
			
		}
		
	} catch (e) {
		
		//if we got here, that means we're on the form 
		
		userConfirmed = confirm('Are you sure you want to retire this asset?');
		
		if (userConfirmed) {
			
			gsftSubmit(null, g_form.getFormElement(), 'retire_asset');
			
		} else {
			
			return false;
			
		}
	}
}

//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
	retireAssets();

function retireAssets() {
	
	current.install_status = 7; //retired
	current.substatus = '';
	current.update();
	
	action.setRedirectURL(current);
	
}