g_list.getChecked() serverside equivalent

hamidouche
Kilo Expert

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

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

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

-Anurag

View solution in original post

6 REPLIES 6

Anurag Tripathi
Mega Patron
Mega Patron

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

-Anurag

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);
}

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

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

Hi,

The business requirement is to display a message in the list with the number of selected records

 

Thanks,

O.H.