Undocumented encoded JOIN query syntax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2020 03:58 PM
All,
I have found a strange piece of code in in the OOTB Script Include "ChangeCollisionHelper":
/**
* Get all the CI GlideRecords that depend on the given CI
*
* return GlideRecord
*/
ChangeCollisionHelper.getCIDependants = function (ciSysId) {
var dependentsGR = new GlideRecord("cmdb_ci");
dependentsGR.addQuery(
"JOINcmdb_ci.sys_id=cmdb_rel_ci.parent!child=" + ciSysId
);
dependentsGR.query();
return dependentsGR;
};
I don't recognize this Syntax.
#1 It looks like an encoded query, but it just uses addQuery.
#2 The comment says that it gets all the cis that depend on the given CI, so that would seem to say that we were looking for its parents. Fascinatingly, "!child=" + ciSysId acts like a Where clause.
This actually works. It's baked into the Script Includes that run the Change module. Is there some documentation that I am just not seeing?
Try this in your PDI if you want to see it work:
var r = getCIDependants('27e52cc8c0a8000b0067d0b66b8a66de');
while(r.next()){
for(var k in r){
gs.print(k + '::' + r[k])
}
}
function getCIDependants (ciSysId) {
var dependentsGR = new GlideRecord("cmdb_ci");
dependentsGR.addQuery(
"JOINcmdb_ci.sys_id=cmdb_rel_ci.parent!child=" + ciSysId
);
dependentsGR.query();
return dependentsGR;
}
Link to the CI parameter record:
https://dev<your instance #>.service-now.com/nav_to.do?uri=cmdb_ci_server.do?sys_id=27e52cc8c0a8000b0067d0b66b8a66de
Regards,
Trey Carroll
- Labels:
-
Scripting and Coding
- 2,313 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2020 04:11 PM
addJoinQuery can help you along
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2020 06:33 AM
The entire crux of my question is regarding the use by ServiceNow in core modules of a strange but powerful, undocumented query string syntax for performing a Where and a JOIN. (Something that we feature requested and were refused ~6 years ago.) The addJoinQuery method is something else. I think that this new functionality it actually an incredible tool.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2020 06:51 AM
This is not new functionality, its been part of the system for a long time. The addJoinQuery allows you to do the same thing as the encoded query you found just not as an encoded query. If you setup a test case and use a addJoinQuery and then use a getEncodedQuery you will see the same syntax. I do agree that the encoded query syntax is not documented but they also left out documentation for related list queries and those have been available for at least 4 years.