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

DVO
Tera Contributor

@Ankur Bawiskar Hi Ankur. This is the field UI Action List, the default value is the sys_id of the UI Action in my code.

find_real_file.png

 

On the list view, it appears as this:

find_real_file.png

Hi,

I am in Quebec release and unable to create field type UI Action list

Regards
Ankur

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

Hi Anwar. This is a field not available to users and can be requested by ServiceNow. However there is a workaround to create it. Please see below: Alternatively, there is a current workaround if you don't want to mess up with the ACLs which maybe a better approach. Please follow the following step: 1. Navigate to sys_dictionary.list 2. Under the 'Type' column, filter it using 'UI Action List' 3. Now, right click on any record in the 'UI Action List' column then click 'Show Matching' 4. Click the new button and you should be able to see the Type prepopulated as 'UI Action List' You can also click on this link which already do the 'Show Matching' for you —> https://[instanceName].service-now.com/nav_to.do?uri=%2Fsys_dictionary_list.do%3Fsysparm_query%3Dinternal_type.labelSTARTSWITHUI%20Action%5Einternal_type%3Dglide_action_list%26sysparm_first_row%3D1%26sysparm_view%3D

Pranesh072
Mega Sage
Mega Sage

You can use rowSysId object to access the sys_id, then you have to do glideajax to get the name and entity.

g_form is not supported on list view.

DVO
Tera Contributor

Hi Pranesh. Thank you for  your response. I am not too worried about that piece of the code as I am looking to simply get the alert to work in list view via the UI Action List field link. How can I modify the code below to satisfy this?

var answer = confirm("Click OK to send consent.");
    if (answer == true) {
        gsftSubmit(null, g_form.getFormElement(), 'Assign_Consent_to_User');