- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2021 07:21 PM
Hi All,
how to write background script to display field data value for a table and related tables.
eg:table:
project_contact >contact>account>contact
Project_contact > Company>contact
Basically i am looking to see which field to use to trigger a survey to send to customer contact once a project is completed.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2021 07:30 PM
Hi,
You don't necessarily need to write a background script to investigate this.
You could just run a quick report, by adding these fields and seeing which look good to use.
But overall, this script would get you started:
var gr = new GlideRecord('project_contract');
//gr.addQuery('sys_id', 'sys_id_here');
gr.query();
if (gr.next()) {
gs.info("The account contact is this: " + gr.contact.account.contact.name + " and the company contact is this: " + gr.company.contact.name);
}
Please use that as an example. This script just quickly grabs any record from the project contract table and looks at it, but you can uncomment my line where I added a query to check a specific sys_id of a record if you know a specific record to check.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2021 07:26 PM
Hope these links help
https://docs.servicenow.com/bundle/paris-application-development/page/script/server-scripting/concept/c_UsingGlideRecordToQueryTables.html
https://community.servicenow.com/community?id=community_question&sys_id=fe0b2b35dbf0e708fff8a345ca96199c

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2021 07:30 PM
Hi,
You don't necessarily need to write a background script to investigate this.
You could just run a quick report, by adding these fields and seeing which look good to use.
But overall, this script would get you started:
var gr = new GlideRecord('project_contract');
//gr.addQuery('sys_id', 'sys_id_here');
gr.query();
if (gr.next()) {
gs.info("The account contact is this: " + gr.contact.account.contact.name + " and the company contact is this: " + gr.company.contact.name);
}
Please use that as an example. This script just quickly grabs any record from the project contract table and looks at it, but you can uncomment my line where I added a query to check a specific sys_id of a record if you know a specific record to check.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!