The CreatorCon Call for Content is officially open! Get started here.

How to use joins in glide record?

msm4
Mega Guru

Hi Team,

Can anyone help in   combine two tables and query that.

5 REPLIES 5

rahulpandey
Kilo Sage

To join tables in ServiceNow, you can use Databaseview.


Database Views - ServiceNow Wiki


Nana5
Mega Guru

Nana5
Mega Guru

Hi Smitha,


Please find the example :



/ Look for Problem records


var gr = new GlideRecord('problem');



// That have associated Incident records


var grSQ = gr.addJoinQuery('incident');



// Where the Problem records are "active=false"


gr.addQuery('active', 'false');



// And the Incident records are "active=true"


grSQ.addCondition('active', 'true');



// Query


gr.query();



// Iterate and print results


while (gr.next()) {


  gs.print(gr.getValue('number'));


}



Thanks


Prakash


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Smitha,



One of my colleagues wrote a couple of blog posts to help out with understanding database views that are really helpful. You might check them out to get a little more info on how they work compared to a sql join.



ServiceNow Admin 101: Observations on Database Views, Part I - Cloud Sherpas


ServiceNow Admin 101: Observations on Database Views, Part II - Cloud Sherpas