The CreatorCon Call for Content is officially open! Get started here.

Combining Tables

sapnasarkar
Tera Contributor

I have two table i have common keys As Cloud in both the table but they are not primary key. How can i combine them. Is there any other way to combine to combine them.

 

17 REPLIES 17

Ravi Gaurav
Giga Sage
Giga Sage

Hello @sapnasarkar 

 

You can create a database view ( https://www.servicenow.com/docs/bundle/xanadu-platform-administration/page/use/reporting/concept/c_D...

or Functional Programming will help you like the below code :-

 

var table1 = 'your_table1';
var table2 = 'your_table2';
var map = {};

var gr1 = new GlideRecord(table1);
gr1.query();
while (gr1.next()) {
var cloudValue = gr1.getValue('cloud');
if (!map[cloudValue]) {
map[cloudValue] = [];
}
map[cloudValue].push(gr1);
}

var gr2 = new GlideRecord(table2);
gr2.query();
while (gr2.next()) {
var cloudValue = gr2.getValue('cloud');
if (map[cloudValue]) {
map[cloudValue].push(gr2);
}
}

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

@sapnasarkar 

he is right. this should work.

@Ravi Gaurav 
I have six tables and the fields in each column is different some might be common i want if in one table it doesn't have that field  then keep empty data for that field.  Let me know how to do this and cloud field is present in all tables