List Choice UI Action on related list - How to rerun server side code

B3N_AU
Tera Guru

Hi,

If you run client and server code for a UI Action on a form. To run the server code after you run the client code. You use 

 

gsftSubmit(null, g_form.getFormElement(), 'action_name');

 

 

If your UI Action is a List choice you need to run 

 

var the_list = GlideList2.get(tablename);
the_list.action(action_id, action_name, sysId);

 

 

All of this is working as expected. What I can't seem to do is run the same UI action from a Related list. I've found that the g_list object is not available for related lists on the form link UI action.

How can this be achieved? I've had a look around and tried various methods but I can't get anything to work?

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@B3N_AU 

that's correct, it won't work in related list.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks Ankur

Guessing that since you didn't offer an alternative that there is no way of doing this by any other means (not using g_list) from a related list?

@B3N_AU 

can you explain what's your business requirement for using that UI action? what's it doing?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

When a user triggers a List choice UI Action on sysapproval_approver to approve a change. There is an extra confirmation for the user approving when the change request is in a blackout or outside of a maintenance window.

 

Inside the Onclick client code. The GlideAjax determines this and returns true or false. Depending on the result, the user is prompted to confirm that they're aware.

This works fine from the Approval list just not from the Approval related list on the Change Request form.

This issue is not being able to re-trigger the UI Action to run the server code from the related list.

 

UI Action

Name: Approve

Table: sysapproval_approver

Action name: approve_list_choice_approval_admin

Onclick: confirmApproval();

function confirmApproval() {

    var apprSysId = g_list.getChecked();
    var ga = new GlideAjax('ChangeUtils');
    ga.addParam('sysparm_name', 'hasBlackoutOrMaintenanceConflict_fromList');
    ga.addParam('sysparm_apprSysId', apprSysId);
    ga.getXML(callback);
}

function callback(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer == 'true') {
        var confirmConflict = confirm('This Change has a Maintenance Window or Blackout Schedule conflict. Press OK to confirm that you\'re aware and are happy to approve the change?');
        if (confirmConflict == false) {
            return false;
        }
    }
    var action_id = "bb863d63c3511200f7d1ca3adfba8f2b"; // sys_id of the UI Action
    var action_name = "approve_list_choice_approval_admin"; // action_name of the UI Action
    var tablename = "sysapproval_approver"; // name of the table for this list
    // Get the GlideList for this table by its tablename
    var the_list = GlideList2.get(tablename);
	var selected = the_list.getChecked(); 
	the_list.action(action_id, action_name, selected);
}

if (typeof window == 'undefined')
    updateAndRedirect();

function updateAndRedirect() {
    current.state = 'approved';
    current.update();
    new ApprovalUserFeedback().approved(current);
  //  action.setRedirectURL(current);
}