What is the difference Query or addQuery?

SS64
Tera Contributor

What is the difference Query or addQuery?

1 ACCEPTED SOLUTION

Namrata Khabale
Giga Guru

Hey SS,

Query: Runs the query against the table,Issue the query to the database to get relevant records.

In order to query a table, first create a ServiceNow object for the table. This object is called a GlideRecord.

query() is a method of class 'GlideRecord'.

 

addQuery: Adds a filter to return records where the field meets the specified condition

 Syntax: addQuery(String name, Object operator, Object value)  //(field, operator, value).

 

Mark correct and helpful if it resolves your issue!!!

 

Best Regards,

Namrata.

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

simply this is the difference

addQuery() ->

  • is used to query against particular field of table;
  • you can have multiple addQuery() statements to query against multiple fields
  • it is not mandatory to use addQuery() everytime

query() ->

  • once you define on which fields with what values you want to query you need to use this function to actually initiate a query to the database table to fetch the required records
  • this is mandatory to use to perform the actual query

Sharing link for reference:

https://docs.servicenow.com/bundle/orlando-application-development/page/script/server-scripting/conc...

Regards
Ankur

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