Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How can I retrieve fields other than the "_ENC_..." sys_id from g_list.getChecked() when the list is being returned from a Database View?

Russ Hancock
Tera Expert

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!

1 ACCEPTED SOLUTION

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.

View solution in original post

5 REPLIES 5

Daniel Oderbolz
Mega Sage

It's quite interesting - the string following __ENC__ looks Base64 encoded, so in the example given by  @kshitiz11 

"YjM2MzNmODBkYmU5MTg1MDg4ZGVhZGMzY2E5NjE5Y2I=-NjExZmU3MGNkYjI5MTg1MDg4ZGVhZGMzY2E5NjE5MGE=-ZTExZmU3MGNkYjI5MTg1MDg4ZGVhZGMzY2E5NjE5MDk=" this decodes 

to "b3633f80dbe9185088deadc3ca9619cb>611fe70cdb29185088deadc3ca96190a>e11fe70cdb29185088deadc3ca961909".

This looks like a list of sys_ids separated by >

 

To me that looks a bit like "security by obscurity" - maybe SN wants to hide the fact that the view records internally seem to have a sys_id (which is indeed a bit crazy - so a view needs to be somehow materialized? Or is some kind of hashing algoithm being used?)

 


If this post was helpful, I would appreciate if you marked it as such - thanks!

Best
Daniel