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

**URL:** <https://community.cumulocity.com/t/how-to-get-all-register-devices-id-in-run-time-custom-widget-code/7672>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [May 4, 2023, 10:43am UTC](https://community.cumulocity.com/t/how-to-get-all-register-devices-id-in-run-time-custom-widget-code/7672 "2023-05-04T10:43:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 4, 2023, 10:43am UTC](https://community.cumulocity.com/t/how-to-get-all-register-devices-id-in-run-time-custom-widget-code/7672/1 "2023-05-04T10:43:52Z")

</div>

#### _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

 ![inventory](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/8/0/80675b647d2f5c761be47a11228ade17a56469c8.png)

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 ?

 ![mo.id](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/e/1/e1282a565ff65966f06add940a931cb5e4031a01.png)

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 .

 ![querylist](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/d/0/d01f5bcf367eeef918667f3286329e4c7a1301c8.png)

#### _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?_

---

<div class="post-metadata">

**Author:** ![Felix.Schaede](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@Felix.Schaede](https://community.cumulocity.com/u/Felix.Schaede)\
**Post date:** [May 15, 2023, 6:29am UTC](https://community.cumulocity.com/t/how-to-get-all-register-devices-id-in-run-time-custom-widget-code/7672/2 "2023-05-15T06:29:34Z")

</div>

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:

```auto
// 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:

```auto
@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:

```auto
const filter = {
      withParents: true,
    };

```

Hope this helps,  
Felix

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 15, 2023, 7:03am UTC](https://community.cumulocity.com/t/how-to-get-all-register-devices-id-in-run-time-custom-widget-code/7672/3 "2023-05-15T07:03:57Z")

</div>

thank you @Felix.Schaede

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [November 11, 2023, 7:04am UTC](https://community.cumulocity.com/t/how-to-get-all-register-devices-id-in-run-time-custom-widget-code/7672/4 "2023-11-11T07:04:43Z")

</div>

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