UI action is working in form view but not working in LIST view

Prasnajeet1
Giga Guru

Hi All

My UI action is working on the form view but not working in the list view. Can someone please help me fixing this issue. Below is the code I have written in UI action.

 

function cancelRequest() {
    //var answer = confirm("Are you sure you want to cancel this request? \nClicking OK will cancel the request. \nClicking 'Cancel' will return to the form. ");
 
    //if (answer == true && g_form.getValue('close_notes') != '') {
if(g_form.getValue('close_notes') != ''){
//alert('Cancelling request and associated records.');
var answer = confirm("Are you sure you want to cancel this request? \nClicking OK will  the request. \nClicking 'Cancel' will return to the form. ");
if(answer == true){
var ga = new GlideAjax('CancelRequest');
ga.addParam('sysparm_name','cancelItems');
ga.addParam('sysparm_record', g_form.getUniqueValue());
ga.getXMLAnswer(cancelResponse);
}
}
 
else if (g_form.getValue('close_notes') == '') {
g_form.setMandatory('close_notes', true);
g_form.showFieldMsg('close_notes', 'Please fill the mandatory close notes', 'error',true);
}
function cancelResponse(response){
var answer = response;
if (answer == "Success"){
alert('Request Canceled Successfully');
} else {
alert('There was a problem cancelling this request. Please contact ServiceNow admins\n\nError Message: \n' + answer);
}
}
}
 
/*
 
if (current.approval != 'approved') {
    current.state = 4;
current.stage = 'closed_incomplete';
} else if {
    current.work_notes = 'User has Requested Closure';
}
current.update();
*/

 

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Prasnajeet1 Since you are using g_form in your UI Action script, it will not work in case of list view, list view contains more than one record and hence g_form.getValue('close_notes')  and g_form.getUniqueValue() will not be available on list view. The same UI Action works on form as the same is available there.

Hi Sandeep

 

Thanks for your quick response. Could you please tell me what need to be use instead of g_form or g_form.getUniqueValue(). If possible could you please change on the above mention script please. It will be very help for me.

Please refer to the solution posted by author here https://www.servicenow.com/community/now-platform-forum/create-ui-action-in-list-and-form-view/m-p/1..., basically he is using an onClick client script function and identifying if the input is coming from the g_list or g_form. You can modify your client side code accordingly.