Announcement

Collapse
No announcement yet.

When did setGlobalValue() become busted for anything beyond a scalar or simple array?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • When did setGlobalValue() become busted for anything beyond a scalar or simple array?

    I see multiple references all throughout the forums on using setGlobalValue/getGlobalValue with objects, etc. and yet this behavior is entirely broken in 12.x.

    setGlobalValue("key", [ 1, [ 2 ] ]) returns [ 1, null ] with getGlobalValue("key")
    setGlobalValue("key", [ 1, volume() ]) can't store the series object for volume(), but does work when not using an array.

    var obj = new Object;
    obj.something = 1;
    setGlobalValue("key", obj) returns null with getGlobalValue("key")

    Why is this function so broken now? If it's not a single dimensional array of a flat value it's simply unreliable to downright unusable.

  • #2
    Use JSON.stringify to store the object as a string then use JSON.parse to convert it back to an object.

    PHP Code:

    var objectTest = new Object;
    objectTest.id =  1;

    setGlobalValue("objectTest"JSON.stringify(objectTest))

    var 
    savedObjectTest JSON.parse(getGlobalValue("objectTest"))
    // Will Print 1
    debugPrintln(saved.id); 

    Comment

    Working...
    X