Script Background to fetch field value from a table

CV1
Tera Contributor

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

find_real_file.png

Basically i am looking to see which field to use to trigger a survey to send to customer contact once a project is completed. 

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

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!

View solution in original post

2 REPLIES 2

Sukraj Raikhraj
Kilo Sage

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

 

Allen Andreas
Administrator
Administrator

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!