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

it will not work .

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

 

you can try something like this

var answer = confirm("Click OK to send consent.");
    if (answer == true) {
        var ga = new GlideAjax('example');// this is the script include
		ga.addParam('sysparm_name', 'doesTableExtend'); // this is the function within the script include
ga.addParam('sysparm_sysid', rowSysId );

		
		ga.getXMLWait();
		doesExtends = ga.getAnswer();

}

DVO
Tera Contributor

Hi Pranesh. I am coming to that conclusion that gsftsubmit does not work as well which is why I brought up the alternative function which is brought up in another thread - glideList2.action()

 

Please see:

"

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
}

"

Sorry i missed that, i updated the code 

var answer = confirm("Click OK to send consent.");
if (answer == true) {

	var sysId = typeof rowSysId == 'undefined' ? gel('sys_uniqueValue').value : rowSysId;
	var action_id = "<sys_id>"; // sys_id of the UI Action
	var action_name = "Assign_Consent_to_User" // action_name of the UI Action
	var tablename = "incident" // name of the table for this list

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

nt6
Kilo Expert

Hi @DVO 

What is the result of this? did you managed to make the script work? I am looking into doing the same thing. Also is there any reason you'd not go the calling GlideAjax path?

 

thx,

EDITED: My requirement was to be able to start server side actions with client confirmation box from ui action list view, and I've found an article from John J. Anderson with fits perfectly of what I need.

Mahendra Chandw
ServiceNow Employee
ServiceNow Employee

The above method does work, but it triggers the server action multiple times,
Basically it triggers the serverScript/ serverside code for each selected item.
which is causing multiple alerts being generated.