GlideList2.action() vs gsftSubmit() for UI Action on List view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2021 03:52 AM
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
}
"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2021 05:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2021 05:38 AM
Hi,
I am in Quebec release and unable to create field type UI Action list
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2021 05:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2021 04:46 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2021 04:50 AM
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');