Power-Fx icon indicating copy to clipboard operation
Power-Fx copied to clipboard

Untyped object: loop through fields of a record

Open MikeStall opened this issue 2 years ago • 3 comments

IUntypedObject can enumerate the property names of an untyped object; but this is not exposed at power fx level.

Request is to treat the Untyped Object like a dictionary and enumerate the keys and get the value for each key.

If X is an UO, either:

Option 1:

ForAll(Keys(x) as K, $"Key={K.Value}, Value={Text(GetField(x, K.value))}")

This requires:

  • enumerating the keys (Keys)
  • as well as dynamic lookup (GetField).
  • efficient dynamic type checks.

GetDisplayName("crf38_name", "crf38_myTable") // "Name"

Option2: GetKeyValues(x) - IEnumerable<string, UntypedObject>

ForAll(GetKeyValues(x), $"Key={ThisRecord.FieldName}, Value={Text(ThisRecord.Value)}")

MikeStall avatar Oct 19 '23 00:10 MikeStall

Can we support Index() on GetKeyValues() ?

jorisdg avatar Oct 19 '23 14:10 jorisdg

Can we support Index() on GetKeyValues() ?

The type of either Keys or GetKeyValues will be a table (either *[Value:s] or *[FieldName:s,Value:O]), and as such the Index function will just work on it.

CarlosFigueiraMSFT avatar Nov 29 '23 16:11 CarlosFigueiraMSFT