Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Getting data from two different tables

Aswanth Suraj
Tera Contributor

Hi Community,  

 

  • I have a situation where I have 2 tables (Table A and Table B).
  • Both tables have Name as common field
  • Table A has fields : Name, number, expiry, etc.
  • Table B has fields : Name, Application name.
  • I want to get the application name from Table B based on the matching of both the Name fields from Table A and B and use that Application name in submitting a catalog request. (This has to be done for all records in Table A)
2 REPLIES 2

Community Alums
Not applicable

Hi @Aswanth Suraj ,

Please refer below script 

var gr = new GlideRecord('tableA'); // Give the backend name of table A
gr.addQuery('active', true);
gr.query();
if (gr.next()) {
	var applicationNameArr= [];
    var grB = new GlideRecord('tableB');// Give the backend name of Table B
    grB.addQuery('gr.name', 'TableB_Name'); // Pass the common name value in table A&B
    grB.query();
	while(grB.next()){
		applicationNameArr.push(grB.application_name.toString()); // Give the backend name of application_name
	}
}

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Thanks for the reply.
But could you tell me where should I use this script and 

AswanthSuraj_0-1716551082483.png

How to bring the application name here. Can you please help?