
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2018 09:20 AM
We are using a Database View (vs. a single table) for displaying our CI Relationships in a related list. On this related list, I am creating a "Delete Relationship" List choice UI Action (displayed on the "Actions on selected rows..." pull-down list). In the script for this UI Action, I am attempting to use the g_list.getChecked() function to return a comma-delimited list of sys_ids from one of the underlying tables in the DB view (cmdb_rel_ci). The sys_id I am trying to retrieve is available in the list, and has a variable prefix of "rel", so this sys_id should be available to the script as "rel_sys_id".
Is there a way to use g_list.getChecked(), or some other means, to retrieve a comma-delimited list of the underlying-table "rel_sys_id" values? Since this list is from a Database View, the ServiceNow-generated "sys_ids" that are currently returned from g_list.getChecked() are at least 187 characters long, and start with "__ENC__...". These encoded sys_ids do not appear to be useful to me as a means to retrieve any values from the underlying tables in this DB View.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 02:05 AM
Just in case, someone needs the exact script, it will be like:
var gr = new GlideRecord('<database_view_name>');
gr.addEncodedQuery('sys_id=__ENC__YjM2MzNmODBkYmU5MTg1MDg4ZGVhZGMzY2E5NjE5Y2I=-NjExZmU3MGNkYjI5MTg1MDg4ZGVhZGMzY2E5NjE5MGE=-ZTExZmU3MGNkYjI5MTg1MDg4ZGVhZGMzY2E5NjE5MDk='); //its a dummy sys_id from getChecked() of my personal instance you need to paste your _ENC_ id here.
gr.query();
if(gr.next()){
gs.print(gr.<table attribute>_<field_name>);
}
Hope it will help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-13-2020 05:16 PM
The question is quite old but since I had the same problem and just found the answer I'd like to provide it to the community.
The word 'encoded' is already giving a hint. A glide record on a database view cannot be used with an "addquery('sys_id', <encodded sys_id from getChecked>)". This fails as the database view pretends not to have an attribute "sys_id".
However, using "addEncodedQuery('sys_id='+<encoded sys_id from getChecked>)" works perfectly to get the correct data set from the database view. Once you got it, you can refer to the sys_id's of the related table objects through "<table prefix>_sys_id" where <table_prefix> is the prefix of the respective table in the database view definition.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 02:05 AM
Just in case, someone needs the exact script, it will be like:
var gr = new GlideRecord('<database_view_name>');
gr.addEncodedQuery('sys_id=__ENC__YjM2MzNmODBkYmU5MTg1MDg4ZGVhZGMzY2E5NjE5Y2I=-NjExZmU3MGNkYjI5MTg1MDg4ZGVhZGMzY2E5NjE5MGE=-ZTExZmU3MGNkYjI5MTg1MDg4ZGVhZGMzY2E5NjE5MDk='); //its a dummy sys_id from getChecked() of my personal instance you need to paste your _ENC_ id here.
gr.query();
if(gr.next()){
gs.print(gr.<table attribute>_<field_name>);
}
Hope it will help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2020 05:36 AM
Thanks Kshitiz1, that definitely helps! I will save this for future reference.
Russ

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2020 05:30 AM
That really helps, thank you Ralfalt! I did manage to get our Delete Relationship UI action working correctly using the getChecked function, but also have a similar issue with our Edit Relationship UI action. For Edit Relationship, I am using the List Context Menu (hover-right-click) for now, which works fine but is a little confusing to users. Applying the same logic I currently have for Delete Relationship did not work for Edit Relationship. I will try your suggestion and let you know if it works for Edit Relationship though.
Thanks again!