How to get all register devices id in run time custom widget code

Product/components used and version/fix level are you on:

Backend: 1015.0.278
UI: 1011.0.38

Detailed explanation of the problem:

I have inventory service in run time widget code here I have getting inventory details of device when passing hardcoded device id but now I want all device id which is register on Cumulocity so that i can pass device id dynamically one by one but i am facing issue I just want to get device id’s ,

below is i have attached screenshot of my run time widget code where i have passed device id hardcoded please check and suggest something so that i can get device id’s

and apart from this below is one more screenshot over there i have mark in red my question is from where we are getting id there is mention mo.id from where i can getting this id ?

below I am attaching one more image where i am getting device name and child device id but I want parent device how to achieve this please refer below attached image .

Error messages / full error message screenshot / log file

Is your question related to the free trial, or to a production (customer) instance?

Have you installed all the latest fixes for the products and systems you are using?

Hi Sumit,

here is a code snipped from the tutorial application that you can use to get a list of all device on creation of a component:

// The filter object will add query parameters
  // to the request which is made by the service.
  private filter: object = {
    fragmentType: 'c8y_IsDevice',
    // paging information will be a part of the response now
    withTotalPages: true,
    pageSize: 10
  };

  constructor(private inventory: InventoryService, public stepperService: StepperService) {
    // _ annotation to mark this string as translatable string.
    //this.informationText = 'Ooops! It seems that there is no device to display.';
    this.loadDevices();
  }

  // Promise-based usage of InventoryService.
  async loadDevices() {
    this.devices = await this.inventory.list(this.filter);
  }

To avoid hardcoding the device id, you can also use the device id that is stored in the widget configuration:

@Input() config;
  
  ngOnInit(): void {
    this.getDevices(this.config.device.id)
  }

To add information about the parent device to the response, you need to add the parameter withParents = true to your filter object:

const filter = {
      withParents: true,
    };

Hope this helps,
Felix

1 Like

thank you @Felix.Schaede

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.