0

I am getting this issue when calling Shared and Recent OneDrive files using MS Graph Client on my modern webpart.

Uncaught (in promise) TypeError: Cannot read property 'id' of undefined

I get the response OK.

using /me/drive/sharedWithMe and /me/drive/recent if I just console.log it lists the ids.

It occurs when pushing the id into the items array.

it works fine with /me/drive/root/children and if I send a drive-id & item id for example /drives/{drive-id}/items/{item_id}/children

if (response) {
    console.log(response)
    response.value.map((item: any) => {
       console.log(item.id)
       items.push({
          key:item.id
          ...
       });
    });
}

I've tried

var i:any;
var item:any;
for (i in response.value) {
   item=response.value[i];
   console.log(item.id)
   items.push({
        key:item.id
        ...
   });
}

Any ideas?

2 Answers 2

0

Works fine when I debug in my local, you could try to debug your code.

enter image description here

enter image description here

2
  • yes this works for me, if I debug without pushing it into an array.
    – AAT
    Jan 29, 2020 at 8:15
  • Can you push in to an array?
    – AAT
    Jan 29, 2020 at 12:31
0

Try below solutions:

var items = response.value.map(obj => ({
    key: obj.id
}))

OR

var items = [];
var len = response.value.length;
for (var i = 0; i < len; i++) {
    items.push({
        key: response.value[i].id,
    });
}

Reference:

How to create an array of object literals in a loop?.

3
  • I've tried these with no success. its strange how it only happens on /me/drive/sharedWithMe & /me/drive/recent
    – AAT
    Jan 29, 2020 at 11:58
  • Are you getting any error while using this solutions? Jan 30, 2020 at 17:31
  • yes its the same error
    – AAT
    Jan 30, 2020 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.