We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

g_list.getchecked not working in declarative action

Sachin G K1
Kilo Sage

Hi All,

when user click ui action, I want to retrieve the sysids selected in the list view of workspace. g_list.getchecked is not working. In Below script alert message is not firing 

 

Declarative Action.png

 

 

Thanks in Advance!

1 ACCEPTED SOLUTION

Hello @Sachin G K1 ,

 

just refer this code :

 

function onClick()

{
var data=g_list.getChecked();

alert(data)

}

View solution in original post

14 REPLIES 14

Hello @Sachin G K1 ,

 

Just for testing can you please remove that parameters from function parenthesis. Then simply check is it working or not .

Hello @Sachin G K1 ,

 

just refer this code :

 

function onClick()

{
var data=g_list.getChecked();

alert(data)

}

Yes, now i am getting sysids. But why not earlier?

Hello @Sachin G K1 ,

 

This might happen due to that parameters . Im glad you query is resolved 😀 . If my response helps you then mark it as helpful and accept as solution. This will helps further future queries.

HaimNizri
Tera Contributor

The issue is that `g_list` isn't available in workspace/UI Builder context like it is in classic UI. Workspace uses a different client-side API.

For workspace list views, you need to use the `snCustomEvent` API to get selected records:

```javascript
// In your UI Action client script
var selectedRecords = [];
snCustomEvent.fire('sn-list-get-selected-items', {
callback: function(items) {
selectedRecords = items;
if (selectedRecords.length > 0) {
alert('Selected records: ' + selectedRecords.length);
// Your logic here
} else {
alert('No records selected');
}
}
});
```

Alternatively, if you're working with a declarative action in App Engine Studio, you might need to handle this server-side instead. Create an action that expects the selected records as input parameters - the workspace will automatically pass them when multiple records are selected.

The key thing to remember is that workspace uses Angular components, not the legacy `g_list` object that's only available in the classic list view.

**If you find my answer useful, please mark it as Helpful and Correct. 😊**