@lionelgo
You are indeed trying to achieve something quite complex. PowerApps generally doesn't support dynamic table and column names like you might see in SQL. PowerApps has a declarative language, Power Fx, which is not designed with dynamic data structures as a first class concept.
In the scenario you've provided, what you're trying to achieve with regex may not be the best approach, as PowerApps doesn't natively support regex operations. Even though your example does use a MatchAll function, which can mimic some of the regex functionality, it's still limited in its scope.
However, it seems that what you're essentially trying to achieve is to turn a JSON string into a table that PowerApps can interact with. PowerApps has a JSON function that can convert JSON to and from collections, which might be more suitable for your purposes.
This formula example should create a collection where each record contains two properties: ColumnName and ColumnValue, from a JSON string:
ClearCollect(
gloJsonCollection,
ForAll(
Split(
Mid(jsonRequestSummary, Find("{", jsonRequestSummary) + 1, Find("}", jsonRequestSummary) - 2),
","
),
{
ColumnName: Trim(First(Split(Result, ":")).Result),
ColumnValue: Trim(Last(Split(Result, ":")).Result)
}
)
)
This formula example should handle JSON strings formatted like {"Name": "John", "Age": "30"}, where each key-value pair is separated by a comma.
Note that this is a simplified version and might not handle more complex JSON strings.
For handling dynamic form creation, I suggest looking at PowerApps' built-in functions, such as:
- AddColumns() to dynamically add columns to your data source,
- UpdateContext() to update screen scope variables based on user input,
- and Patch() to update your data source with these changes.
Remember, you cannot use Set() here because it could cause issues later when you want to patch the data, as per Patch requiring the first argument to be a Collection, which means it also cannot be a global variable by Set even if it's a Table.
You could also name your global variables with the prefix 'glo', as in 'gloJsonCollection' to distinguish them from say context variables.
See if it helps @lionelgo