- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2017 07:24 AM
Can anyone explain me what does this query pull or mean in the below scripts mean?
Script :
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id', current.caller_id);
gr.query();
Q1) I dont understand how sys_id (Alpha-numerical value) is compared to caller_id(If i'm not wrong its the name of the caller on a table like incident).
I understand gr.addQuery('Active', true);
Pulls the records that are active, but querying with sys_id is very confusing.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2017 05:02 PM
Q1) The dictionary name of the caller field is caller_id?
Yes. The label says "Caller", but if you right click on the label and choose "Show caller_id" it will clearly indicate that the underlying database field name is "caller_id". Labels can differ, and often do when multiple languages are involved, from the database field name. No harm in that. Just the flexibility and power of the platform.
Q2) And it is a reference type field referring to user name?
Close. It is a reference field type referring the user table (which in the database is called sys_user).
But i guess ServiceNow recognizes, caller_id as reference to sys_id of the caller/user not the name of the caller/user.
Internally, the value of the caller_id field is a sys_id, a GUID as some system call it. It's a unique record identifier to a record in the sys_user table. This means that if you have five people with the same name (John Smith), they are all separate because they have different sys_ids on each record. All records in ServiceNow tables have unique sys_ids for each record.
Q3) The confusion is caller_id gives name of the user (string) or the sys_id of the user(alphanumeric)
When you use a sys_id to refer to a record in another table, the other table (in this case sys_user) has one field that is defined as the "display" field. In this case, the 'name' field is displayed for humans to read when you fill in the field value for "Caller" (caller_id). Because let's face it, few humans would be able to read a 32-character hex string and say "That's Shalini!". It's easier to read the value of the name field. In ServiceNow speak, you may hear this referred to as the "display value". It's one of the fields to show to humans instead of the sys_id. If you start seeing sys_ids in reference fields you know something has gone wrong.
Q4) Every record in all the tables have a unique ID which sys_id? If this is true, why look for matching sys_IDs?
Yes, that's true. All records have a unique sys_id associated with each record they contain as explained above. See my response below for the second part of your question.
For example:
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.query();
So if the attachment record with sys_id (table_sys_id) is a unique ID and current incident sys_ID is unique ID. Then why/how matching?
This might help... the sys_attachment table has a number of records. Each has their own sys_id. Unfortunately, you don't know the sys_id for the attachments that show up on your incident (or whatever.) Let's say you are looking at Incident INC001005 (sys_id 1A2B3C). You want to find incidents related to this record and know the table name (incident) and sys_id of the incident (1A2B3C), so you can find all attachments like this:
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('table', current.getTableName());
gr.query();
That says "Find me all the attachments that are related to this record on and this table. It's a bit like saying "Find all the users in the user table with first name John and last name Smith."
I hope that helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2017 05:02 PM
Q1) The dictionary name of the caller field is caller_id?
Yes. The label says "Caller", but if you right click on the label and choose "Show caller_id" it will clearly indicate that the underlying database field name is "caller_id". Labels can differ, and often do when multiple languages are involved, from the database field name. No harm in that. Just the flexibility and power of the platform.
Q2) And it is a reference type field referring to user name?
Close. It is a reference field type referring the user table (which in the database is called sys_user).
But i guess ServiceNow recognizes, caller_id as reference to sys_id of the caller/user not the name of the caller/user.
Internally, the value of the caller_id field is a sys_id, a GUID as some system call it. It's a unique record identifier to a record in the sys_user table. This means that if you have five people with the same name (John Smith), they are all separate because they have different sys_ids on each record. All records in ServiceNow tables have unique sys_ids for each record.
Q3) The confusion is caller_id gives name of the user (string) or the sys_id of the user(alphanumeric)
When you use a sys_id to refer to a record in another table, the other table (in this case sys_user) has one field that is defined as the "display" field. In this case, the 'name' field is displayed for humans to read when you fill in the field value for "Caller" (caller_id). Because let's face it, few humans would be able to read a 32-character hex string and say "That's Shalini!". It's easier to read the value of the name field. In ServiceNow speak, you may hear this referred to as the "display value". It's one of the fields to show to humans instead of the sys_id. If you start seeing sys_ids in reference fields you know something has gone wrong.
Q4) Every record in all the tables have a unique ID which sys_id? If this is true, why look for matching sys_IDs?
Yes, that's true. All records have a unique sys_id associated with each record they contain as explained above. See my response below for the second part of your question.
For example:
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.query();
So if the attachment record with sys_id (table_sys_id) is a unique ID and current incident sys_ID is unique ID. Then why/how matching?
This might help... the sys_attachment table has a number of records. Each has their own sys_id. Unfortunately, you don't know the sys_id for the attachments that show up on your incident (or whatever.) Let's say you are looking at Incident INC001005 (sys_id 1A2B3C). You want to find incidents related to this record and know the table name (incident) and sys_id of the incident (1A2B3C), so you can find all attachments like this:
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('table', current.getTableName());
gr.query();
That says "Find me all the attachments that are related to this record on and this table. It's a bit like saying "Find all the users in the user table with first name John and last name Smith."
I hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2017 10:55 PM
Wonderful!
Thank you Chuck! The example is very clear.
I understood now. Thank you all for your responses.
Will keep bugging you all till i learn things perfectly.
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 05:18 AM
If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
If you are viewing this from the community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 06:31 AM
Chuck/Pradeep,
I'm trying to learn ServiceNow Development/Administration.
Could you help me with real-time scenarios for the below to practice please.
- Set up an end-to-end email notification using a business rule trigger.
- Send an email notification from graphical workflow.
- Trigger an event from graphical workflow that sends an email.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2017 07:14 AM
Hi Shalini,
There are examples of these OOB. I don't have the opportunity at the moment to find each of them. The wiki and docs sites are very good at walking you through how to build each one of these. I invite you to review the below links.
Scripting for Email Notifications - ServiceNow Wiki
Email Notifications - ServiceNow Wiki
Notification Activities - ServiceNow Wiki
Create Event workflow activity
Events and Email Notification - ServiceNow Wiki