- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 08:43 AM
Hi Expert,
Thanks in advance and sorry for my english.
My question is while writing the script on ,sc_catalog, sc_category, sc_cat_item ,sc_request, sc
_req_item, sc_task table how to apply add query .
how to match the query between to table.
For EG:
var grItem = new GlideRecord('sc_req_item');
grItem.addQuery('sys_id',current.parent);
or
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', current.sys_id);
in this script grItem.addQuery('sys_id',current.parent); and gr.addQuery('sys_id', current.sys_id);
I dont understand how to apply this
Please explain me , I will really appreciate .
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 09:33 AM
Hi,
So sys_id the unique/primary key for any record.
Lets take an example:-
,sc_request _> sc_req_item -> sc_task table
sc_request is the parent of sc_req_item and sc_req_item is the parent of sc-task
Now if you want to search for a records in sc_task which has the same sc_req_item, you would use the below:-
var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id', current.request_item);
Above sys_id is the primary key while request_item is the field which store the RITM on the Catalog task table as RITM is parent of sc_task
gr.addQuery('sys_id', current.request_item); This is generally used when two tables have any sort of connect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 09:33 AM
Hi,
So sys_id the unique/primary key for any record.
Lets take an example:-
,sc_request _> sc_req_item -> sc_task table
sc_request is the parent of sc_req_item and sc_req_item is the parent of sc-task
Now if you want to search for a records in sc_task which has the same sc_req_item, you would use the below:-
var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id', current.request_item);
Above sys_id is the primary key while request_item is the field which store the RITM on the Catalog task table as RITM is parent of sc_task
gr.addQuery('sys_id', current.request_item); This is generally used when two tables have any sort of connect
Hope this helps. Please mark the answer as correct/helpful based on impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 09:54 AM
Hi,
Please see the response below to achieve your requirement:
For Example let's take two tables "Request" and Requested item".
Before doing a Glide Record you need to understand the table structure against which you are planning to write your query, so in order to write your addQuery first thing you need to find out which is the common field which connects both of your Tables and then that field which is connecting your Tables, will be in your addQuery.
Now depending on your Table on which you are applying GlideRecord, first field in addQuery will be a field from the Table on which you have applied GlideRecord on. For example for the above two tables, there is a Field called Request present on requested item table which connects both of them.
So Now if you apply a GlideRecord on Request Table then your script will look like below:
var gr = new GlideRecord('sc_request');
gr.addQuery('Give Field present on sc_request Table which connects both of them',current.sys_id);// current because assuming BR is written on RITM table or use the object say gr or anything else;
gr.query();
Please go through below docs to understand this better:
This articles explains clearly how to learn on addQuery and GlideRecord:
https://docs.servicenow.com/bundle/rome-application-development/page/script/server-scripting/concept/c_UsingGlideRecordToQueryTables.html
https://community.servicenow.com/community?id=community_question&sys_id=653bb53edbf1dc102737e15b8a9619eb
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 11:58 PM
Thanks sourav and sholke for response ,Its helpful but still i am confused how to check common field between both table, If u share some screenshot it will be really helful for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2022 12:18 AM
Hello Sonali,
If there is a reference field present on any table that means now connected.
Reference fields are fields where we can select values from other fields:-
Marked in blue above are example of reference fields.
If there is a reference field present on any form that means using that field we can glide to other tables and vice versa
Hope this helps. Please mark the answer as correct/helpful based on impact.
Hope this helps. Please mark the answer as correct/helpful based on impact.