inc.query();

Veena18
Tera Contributor

Is inc.query(); is necessary to execute a script 

or  can we use any alternatives instead of inc.query();

3 ACCEPTED SOLUTIONS

siva krishna M2
Tera Guru

Hello @Veena18 ,

 

To fetch single record from any table using GlideRecord and using one field value(ex:sys_id) on record with we can go with rec.get(sys_id) and no need to use rec.query().

To get Multiple records for all the addQuery's in the script of GlideRecord needs .query() to fetch the records from the table.

 

If my response is useful, then kindly mark it as "Accept as Solution" and " Helpful."

This helps community and as well as

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@Veena18 

without query() function the GlideRecord won't query the table and you won't be able to iterate the result

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

Ayushi12
Mega Sage

@Veena18 
query() function in ServiceNow's GlideRecord API is used to retrieve records from tables in the ServiceNow database. It executes the query.

Refer:https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_script...
https://docs.servicenow.com/bundle/vancouver-api-reference/page/script/server-scripting/concept/c_Us...

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

4 REPLIES 4

NVSN
Tera Contributor

Hi @Veena18,

Query(Example: br.query or inc.query) is a mandatory method while working with GlideRecords.

 

If my response is useful, then kindly mark it as "Accept as Solution" and " Helpful."

This helps community and as well as me.

 

Thanks.

siva krishna M2
Tera Guru

Hello @Veena18 ,

 

To fetch single record from any table using GlideRecord and using one field value(ex:sys_id) on record with we can go with rec.get(sys_id) and no need to use rec.query().

To get Multiple records for all the addQuery's in the script of GlideRecord needs .query() to fetch the records from the table.

 

If my response is useful, then kindly mark it as "Accept as Solution" and " Helpful."

This helps community and as well as

Ankur Bawiskar
Tera Patron
Tera Patron

@Veena18 

without query() function the GlideRecord won't query the table and you won't be able to iterate the result

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ayushi12
Mega Sage

@Veena18 
query() function in ServiceNow's GlideRecord API is used to retrieve records from tables in the ServiceNow database. It executes the query.

Refer:https://developer.servicenow.com/dev.do#!/learn/courses/utah/app_store_learnv2_scripting_utah_script...
https://docs.servicenow.com/bundle/vancouver-api-reference/page/script/server-scripting/concept/c_Us...

Please mark this response as correct or helpful if it assisted you with your question.