I'm trying to get my head round promises and so far it's very frustrating !
I am calling a method in the console that returns a promise like this :
getSharepointListItems("count")
The result of the call is :
Promise {<pending>}
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: Array(1)
0: {ContentTypeId: SP.ContentTypeId, Title: "400000", _ModerationComments: null, File Type: null, ComplianceAssetId: null, …}
length: 1
__proto__: Array(0)
I want assign the 400000
to a variable and use it for further calculations, but im unable to capture it.
I read that i should chain a .then
to my method call, which i understand also returns a promise. So i tried:
getSharepointListItems("PalletCounter").then( (r) => console.log(r))
And the result now is:
Promise {<pending>}
VM1315:1
[{…}]
0: {ContentTypeId: SP.ContentTypeId, Title: "400000", _ModerationComments: null, File Type: null, ComplianceAssetId: null, …}
length: 1
__proto__: Array(0)
So the [[PromiseValue]]: Array(1)
has now been replaced by what looks like an object in an array, but there is also a promise which is pending
, which i don't understand.I'm still unable to get to the 400000 value/result. Chaining more .then
does not make a difference. I still get the above result.
How do i go about retrieving the result and saving it to a variable?
thanks