Calling ‘cmdb_ci_hardware’ table join additional attributes only available in ‘cmdb_ci_printer’
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 06:49 AM
- Calling ‘cmdb_ci_hardware’ table join additional attributes only available in ‘cmdb_ci_printer’:
- Printer Management
- Consumable Ship To
In REST API only one table can be invoked. how invoke both tables in API and how obtain this output. Appreciate your expertise.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 08:20 AM
use scripted rest API..
var sysId = request.queryParams.sys_id; // add any thing
var hardwareGR = new GlideRecord('cmdb_ci_hardware');
if (hardwareGR.get(sysId)) {
var printerGR = new GlideRecord('cmdb_ci_printer');
printerGR.addQuery('fieldName', hardwareGR.sys_id); // add which field referenced to hardware table
printerGR.query();
var printerData = {};
if (printerGR.next()) {
printerData = {
consumable_ship_to: printerGR.consumable_ship_to,
printer_management: printerGR.printer_management
};
}
// Combine data from both tables
var combinedData = {
hardware: {
name: hardwareGR.name,
model_id: hardwareGR.model_id
},
printer: printerData
};
response.setBody(combinedData);