0

Trying to extract from a promise, see below. The value that I'm trying to extract is the "mObjectUUID:".

Able to pull back the promise through "resolveProductNodes().then()" but unsure then how to extract the ID. Can you help?

Promise {<fulfilled>: Array(1)}
[[Prototype]]
: 
Promise
catch
: 
ƒ catch()
constructor
: 
ƒ Promise()
finally
: 
ƒ finally()
then
: 
ƒ then()
Symbol(Symbol.toStringTag)
: 
"Promise"
[[Prototype]]
: 
Object
[[PromiseState]]
: 
"fulfilled"
[[PromiseResult]]
: 
Array(1)
0
: 
S {mObjectId: 1, mObjectUUID: 'e4702625-15ce-a6c8-b88e-b790e7e47224', mMessageHandlers: {…}, mComponents: Array(7), mRenderObject: h, …}
length
: 
1
[[Prototype]]
: 
Array(0)

I tried "resolveProductNodes().then()" but then unsure how to extract the ID. Can you help?

  • The argument to the `.then()` callback is whatever the promises's function passed when it called `resolve()`. – Barmar Nov 18 '22 at 16:06

1 Answers1

0

The .then() callback function receives the object as its argument. You can then extract properties from that.

It looks like the resolved value is an array, you need to index it.

resolveProductNodes().then(res => console.log(res[0].mObjectUUID));
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks Barmar. Ran the code in the console however it's coming back undefined. Is there anything else I should be doing? – griffen Nov 18 '22 at 16:42
  • Please post a [mre] that shows the promise code. It's hard to tell what's really going on from the output you showed. – Barmar Nov 18 '22 at 16:46
  • Ran the code: window.expivi.resolveProductNodes().then(res => console.log(res.mObjectUUID)); Output is: undefined Promise {: undefined} [[Prototype]] : Promise [[PromiseState]] : "fulfilled" [[PromiseResult]] : undefined – griffen Nov 18 '22 at 18:37
  • I need to see the code for `resolveProductNodes()` to see how it calls `resolve()` – Barmar Nov 18 '22 at 19:11
  • Try `res[0].mObjectUUID`. It looks like the value is an array. – Barmar Nov 18 '22 at 19:12
  • Not quite. Got the error message: Uncaught ReferenceError: resolveProductNodes is not defined at :1:1 – griffen Nov 19 '22 at 22:47
  • If the function isn't defined, that's a completely different problem. – Barmar Nov 20 '22 at 22:36