How to Fetch the 2 tables data from reference qualifier using script include in a catalog item field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2023 05:48 AM
Hi All ,
I have a requirement in catalog item for specific field(Contact) and referenced to contact table.
if i click on lookup, then it should show all the contacts and contact relationship (there is a custom table) data, but in type specification i can give as reference 1 table(ex:contact) but there is another table to fetch the data.
could you please explain the script include for gliding another table from array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2023 08:36 AM
Hi, I recommend to create a db view to merge the 2 tables and use the DB view in the reference qualifier to achieve your requirement.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2023 09:20 AM
Hi, I recommend to create a db view to merge the 2 tables and use the DB view in the reference qualifier to achieve your requirement.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2024 07:23 PM
can we use db view in reference field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-23-2024 08:08 PM
@Ramesh1532 To fulfill this requirement in ServiceNow, you can use a Script Include that queries both tables (contact and your custom relationship table) and returns a combined result.
Script Include will look like below and feel free to modify as needed:
var CustomContactLookup = Class.create();
CustomContactLookup.prototype = {
initialize: function () {},
getCombinedContacts: function () {
var result = [];
// Query the 'contact' table
var contactGR = new GlideRecord('contact');
contactGR.query();
while (contactGR.next()) {
result.push({
sys_id: contactGR.getValue('sys_id'),
name: contactGR.getValue('name'), // Update the field names as per your table
});
}
// Query the custom relationship table
var relationshipGR = new GlideRecord('your_custom_relationship_table');
relationshipGR.query();
while (relationshipGR.next()) {
result.push({
sys_id: relationshipGR.getValue('sys_id'),
name: relationshipGR.getValue('related_name'), // Update the field names as per your table
});
}
return result;
},
type: 'CustomContactLookup'
};
Hope this will help you.