SubQuery usage in Encoded Queries.

Mohan37
Tera Contributor

Hi All,

I just noticed the below code in one of the Relationships. Can you please explain "SubQuery" ? 

current.addEncodedQuery("SUBQUERYsys_id,document_id,interaction_related_record^interaction=" + parent.sys_id + "^ENDSUBQUERY");

 

Applies to Table: Interaction

Query from Table : Task

 

Thanks,

Mohan

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Mohan,

refer below link for help

addJoinQuery method in GlideRecord

Regards
Ankur

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Mohan,

refer below link for help

addJoinQuery method in GlideRecord

Regards
Ankur

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

Thejeswar Nagir
ServiceNow Employee
ServiceNow Employee

Hi Mohan,

Adding on Ankur's reply...

If you open the sys_relationship entry (which you are referring to here), the "Queries From Table" is Task and the encoded query is "SUBQUERYsys_id,document_id,interaction_related_record^interaction=" + parent.sys_id + "^ENDSUBQUERY", meaning, it is joining the task table with the interaction_related_record table on task.sys_id = interaction_related_record.document_id... and on top of that, they are adding a filter condition (interaction_related_record.interaction= <current Interaction Object's sys_id>), just to display the ones related to the current Interaction record in the Related List.

the above encoded query gets translated to something like this...

var gr = new GlideRecord('task');

var intGr = gr.addJoinQuery('interaction_related_record', 'sys_id', 'document_id');

intGr.addCondition('interaction', <current Interaction Object's sys_id>);

gr.query();

Thanks

Thejeswar N