query Database view

srinivasr
Mega Contributor

I have a need where i need to join two tables incident(extended from task table) and new table (not an extended/reference once)

So I created a view out of these two tables.

How can i query the database view now ?   Will the GlideRecord work the same way it would work for tables or do i need to use gs.sql ?

1 ACCEPTED SOLUTION

creatiga
Tera Contributor

You can query the database view, but you need to use the prefix before a field name. For example if you have a database view where the incident prefix is inc; then you will need to use it when you query the table:

 

var gr = new GlideRecord('your_database_view_table')

gr.addQuery('inc_active', true);

gr.query();

while(gr.next()){

your code here

}

 

View solution in original post

3 REPLIES 3

manikorada
ServiceNow Employee
ServiceNow Employee

You can't query Database view using GlideRecord.


If you want to join these two tables and use GlideRecord, you can use : http://wiki.servicenow.com/index.php?title=GlideRecord#addJoinQuery&gsc.tab=0


Thanks Mani for answering my question. I am able to join the tables using the addJoinQuery api.


But my ultimate goal is to get an left outer join out of that ? How this can be achieved ??


creatiga
Tera Contributor

You can query the database view, but you need to use the prefix before a field name. For example if you have a database view where the incident prefix is inc; then you will need to use it when you query the table:

 

var gr = new GlideRecord('your_database_view_table')

gr.addQuery('inc_active', true);

gr.query();

while(gr.next()){

your code here

}