Hi Mitchell,
Directly addressing your issue and code, you can in fact get it through reflection like you are trying to do.
You just need to access the actual structure (ssSTPayload) within the record. You will also need to exclude the "OptimizedAttributes" attribute that is injected by default.
You can try this (and adjusting accordingly your outputs and string building, etc):
// Your Current, or simillar
var outputString = string.Empty;
foreach (var f in payload.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
outputString += $"Name: {f.Name} | Value: {f.GetValue(payload)}\n";
}
//Try this
var testOutputString = string.Empty;
foreach (var f in payload.ssSTPayload.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
{
if (!f.Name.Equals("OptimizedAttributes"))
{
testoutputString += $"Name: {f.Name} | Value: { f.GetValue(payload.ssSTPayload)}\n";
}
}
The above being said, you could also provide as an input, a List of Key-Value Records, each one representing an attribute of your payload.
Your "Payload" input would be something like:
Payload:
DataType: RecordList, RecordDefinition: KeyVaueRecord
KeyValueRecord:
Attributes:
Key: Text
Value: Test
Representation: [{Key: "merchant_id", Value: "something"}, {Key: "merchant_key": Value: "something"} etc..]
This would make it easier on the extension to just iterate the list and pull each Key Value, completely dynamic.
It also makes it easier on the record definition as you mention that "(...)there will be many more coming".
There is of course, the trade-off that you have to prepare the "Payload" list of Key Value Records before hand on Outsystems.
I will suggest you the following article if you don't mind, from Outsystems MVP João Marques:
https://medium.com/@jsmarques13/integrating-dynamic-structures-with-outsystems-6c45e36a4d47
Hope it helps,
Nuno