Q: Why can I not access the properties of my CRF context parameter?
Consider the Attributes property of an Assertion Record.
The following rule returns a collection of key values when invoked from the Rule Tester:
Filter(Attributes.Keys, EndsWith(context, "Rule"))
But when the same command is attempted within the function below:
GetProbe(rulePrefix, attrDict)
Filter(attrDict.Keys, StartsWith(context, rulePrefix))
... an error is returned as follows:
Unable to calculate rule GetProbe("active Admin", Attributes) for object Unit Test Example (<guid>):
Unable to find field or property rulePrefix on String, and String does not support indexing
Reducing the function body to the following:
StartsWith(context, rulePrefix)
... results in no error being raised, but no results are returned either.
How should a function be written to return a subset of keys from the supplied dictionary parameter?
A: Because to do this you need to specify parentContext when supplying a list to a CRF.
Consider the GetProbe function as specified above.
In each iteration of Filter, context is a string key, which does not have a rulePrefix property (which is from the parent context).
Instead you should specify the content of your CRF as follows:
Filter(attrDict.Keys, StartsWith(Child, Parent.rulePrefix), parentContext=context)
By passing the parentContext, each iteration of Filter applies to a structure that looks like this:
{ Child: <listitem>, Parent: <parentContext object> }
This behavior generalizes across all of the List/Enumerable processing functions.
Comments
0 comments
Please sign in to leave a comment.