Web Connection
Return property of type array with undefined value
Gravatar is a globally recognized avatar based on your email address. Return property of type array with undefined value
  Harvey Mushman
  All
  Nov 23, 2018 @ 07:33pm

Do you know of a way on a REST response to return a property of Array type without defining a value?

DIMENSION Counties(1)
ADDPROPERTY(loResults,'Counties[' + TRANSFORM(1) + ']')

The default value seems to be "false" rather than "undefined" even though no value was specified. And assigning .null. returns just that... null.

Or do I need to trap for this in the Javascript on the client side?

Thanks

PS Happy Turkey Day!

Gravatar is a globally recognized avatar based on your email address. re: Return property of type array with undefined value
  Rick Strahl
  Harvey Mushman
  Nov 24, 2018 @ 11:30am

Arrays can't be returned in FoxPro - it's an illegal operation.

If you're serializing to JSON return a Collection or wwCollection or a cursor, all of which will be serialized into a JSON array. If necessary you can use ArrayToCollection().

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Return property of type array with undefined value
  Harvey Mushman
  Rick Strahl
  Nov 24, 2018 @ 06:37pm

Thanks for the answer, I am returning a collection so I've added the array to it but since it can be empty, I still need a value that will never come up as real data. I think I will assign .null. as a value and then trap for it on the client where I will convert null to unassigned.

Thank again for your thoughts.

Gravatar is a globally recognized avatar based on your email address. re: Return property of type array with undefined value
  Rick Strahl
  Harvey Mushman
  Nov 24, 2018 @ 11:32pm

The way to return empty arrays is to return an empty collection. Usually that's better because you don't have to have the extra null check.

+++ Rick ---

© 1996-2024