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

Calling ‘cmdb_ci_hardware’ table join additional attributes only available in ‘cmdb_ci_printer’

sathishasho2525
Tera Contributor
  1. 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. 

 

sathishasho2525_1-1726235318914.png

 

1 REPLY 1

Mani A
Tera Guru

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);