- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2020 09:00 AM
Hi,
I have a button on a list and I would like to display a message on the list saying how many records have been selected once I click the button:
gs.addInfoMessage(' You selected ' + numberOfSelectedRecords + ' records');
where numberOfSelectedRecords would be constructed as follows:
var checked = g_list.getChecked();
var arr= [];
arr = checked.split(',')
var numberOfSelectedRecords = arr.length;
the problem is that g_list.getChecked() is client side only. Is there an equivalent serverSide?
Thanks,
OH
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2020 09:03 AM
Hi,
Unfortunately there is no serverside equivalent of this. But what i use alternatively is a ui action which has server and client side code both, check the link below
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Using the above i use client side code g_list.getChecked(); to select the rows selected and pass them to server side to process further.
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2020 09:03 AM
Hi,
Unfortunately there is no serverside equivalent of this. But what i use alternatively is a ui action which has server and client side code both, check the link below
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Using the above i use client side code g_list.getChecked(); to select the rows selected and pass them to server side to process further.
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2020 10:02 AM
Using the above i use client side code g_list.getChecked(); to select the rows selected and pass them to server side to process further.
How would you do that? it's not working.
function clientSideFunc() {
var checked_elements = g_list.getChecked();
var arr = [];
arr = checked_elements.split(',');
var numberOfSelectedRecords = arr.length;
alert(numberOfSelectedRecords);
serverReopen(numberOfSelectedRecords)
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'action_name'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverReopen();
function serverReopen(selectedRecords) {
gs.info('number of records selected' + selectedRecords);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2020 10:05 AM
Hi,
unfortunately you cannot pass data from client side to server side in same UI Action
what is your business use-case/requirement here
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
06-03-2020 10:11 AM
Hi,
The business requirement is to display a message in the list with the number of selected records
Thanks,
O.H.