GlideList2.action() vs gsftSubmit() for UI Action on List view

DVO
Tera Contributor

Hi All.

I have added a field type UI Action List, which enables UI Actions to appear as a clickable link via list view. I am looking to add an alert before the UI action is executed but cannot seem to get it to work via the list view. The code works as expected via the form. 

Through some deep digging, I've found another user claim the following: 

gsftSubmit() will not work from the List view because g_form is not defined, so there is no form element to provide (which is the second parameter required by gsftSubmit()). 

GlideList2.action() is an undocumented g_list function that will achieve the same effect on List view as gsftSubmit() does on the Form view.  

Has any one run into this scenario? How can I modify the client part of my code so it enables the alert on the list  view in the same way that it does on the form?

 

 

function sendConsent() {
    var name = g_form.getValue('first_name');
    var entity = g_form.getValue('u_consent_entity');
    var answer = confirm("Click OK to send " + name + " a " + entity + " consent.");
    if (answer == true) {
        gsftSubmit(null, g_form.getFormElement(), 'Assign_Consent_to_User');



    } else {
        return false;
    }
}

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

function generateConsent() {
    var consentEntity = current.u_consent_entity;
    var survey = new GlideRecord('asmt_assessment_instance');
    survey.addQuery('user', current.sys_id);
    survey.addEncodedQuery('state!=complete^metric_type=10644d92dba124d0629a6f8b139619e3^ORmetric_type=4086c3501b4aa85090638622604bcbba^ORmetric_type=a88883541b4aa85090638622604bcbb6^ORmetric_type=dc188f141b4aa85090638622604bcb84^ORmetric_type=53f8cb941b4aa85090638622604bcbc8^sys_created_onRELATIVELT@dayofweek@ahead@120');
    survey.orderByDesc('sys_created_on');
    survey.setLimit(1);
    survey.query();

    if (survey.next()) {
        gs.addInfoMessage(survey.metric_type.getDisplayValue() + " record already exists and is pending a response. Please advise " + current.first_name + ' ' + current.last_name + " to check their Now Mobile app.");

    } else{

        (new SNC.AssessmentCreation()).createAssessments('10644d92dba124d0629a6f8b139619e3', '', current.sys_id);
        gs.addInfoMessage("Consent has been sent to " + current.first_name + ' ' + current.last_name + " at " + current.email + ".");

   
    }
}

 

I am refering back to this reply:

"

I know this post is quite old, but in case anyone else is wondering, I could not find this answer anywhere else on Community.

gsftSubmit() will not work from the List view because g_form is not defined, so there is no form element to provide (which is the second parameter required by gsftSubmit()). 

GlideList2.action() is an undocumented g_list function that will achieve the same effect on List view as gsftSubmit() does on the Form view.  You can use it as follows:

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

Here is a fuller example script, which also shows how to get only the selected sys_ids which are allowed by the UI Action's condition:

Name:  Example Action
Sys ID: 0123456789abcdef0123456789abcdef
Table:  incident
Action name: example_action
Client: true
Onclick: clientScript()

function clientScript() {
  // Do client-side things, like a confirmation popup

  // After client-side things are done
  var action_id = "0123456789abcdef0123456789abcdef"; // sys_id of the UI Action
  var action_name = "example_action" // action_name of the UI Action
  var tablename = "incident" // name of the table for this list

  // Get the GlideList for this table by its tablename
  var the_list = GlideList2.get(tablename);

  // Get the checked values which this action is allowed for
  // First try checking gsft_allow, fall back on GlideList2.getChecked()
  var selected = gel(action_id).getAttribute("gsft_allow");
  if (selected === null || selected === "") {
    selected = the_list.getChecked(); 
    if (selected === null || selected === "") {
      return; // Couldn't find any selected values
    }
  }
  
  // Re-run the action on the server side
  the_list.action(action_id, action_name, selected);
}

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

function serverScript() {
  // Do server-side things
}

"

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

what type of UI Action it is?

Is it list choice? If yes then g_form won't work

Regards
Ankur

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

It is a UI Action List field - which displays as a link in a column in the list view. Similar to how for update sets, there are clickable links as UI actions eg Accept Update Set, Skip Update Set etc. This is not a field which ServiceNow has public accessible and must be requested from them to add.

See example.

find_real_file.png

Hi,

please share the UI Action screenshot

Regards
Ankur

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