Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
6 replies
Subscribers
7 subscribers
Views
2084 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
In order to make a general purpose sub-process to do some lookups in an external
tmalaher
over 10 years ago
In order to make a general purpose sub-process to do some lookups in an external system, I want to return a key-value map to the calling process. In Appian this type of data structure seems to be known as a "dictionary".
The problem is that I don't see how the keys can be generated dynamically...
I can do this:
{key1: ri!value1, key2: ri!value2}
But then the keys are hardcoded.
If I do:
{ri!key1: ri!value1, ri!key2: ri!value2}
the result is (in the rule tester): [key1:xxx,key2:yyy]
i.e. the "ri!" is ignored and the key becomes the NAME of the rule input variable, rather than the VALUE of the rule input.
I can arrange to have an array of keys and an array of corresponding values, and there's a "merge()" function that would group them, but the result is just an array of arrays, grouped properly, but that's not a dictionary.
Is there something that would turn the result of a merge() into a dictionary, or some other way to dynamicall...
OriginalPostID-114385
OriginalPostID-114385
Discussion posts and replies are publicly visible
0
tmalaher
over 10 years ago
...y generate a dictionary?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 10 years ago
Take a look at the keyval function. That might help you.
forum.appian.com/.../Text_Functions
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
tmalaher
over 10 years ago
Thanks for the pointer.
With suitable application of apply, reduce, and merge to fn!insertkeyval, I was able to create a text string like this: [first=John][last=Smith]
I can then use keyval() to extract "first" or "last" from that.
So this works, but it has to create and parse a string representation to do it, which seems inefficient, not to mention fragile and problematic.
Will it work if the values contain newlines? What if the keys contain "=" or if the keys or values contain "]"?
I'll try some things and see if this could work out.
But why can't we just create a dictionary directly? I suppose I could write a custom scripting function that would construct and return a dictionary given a set of keys and values (or an array of two-element arrays) as input...
But I'd rather not have to write Java code and keep it maintained across upgrades.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
elizabeth.epstein
over 9 years ago
I'm not sure I completely understand your use case, but why not create your own CDT called KeyValue which is just 2 text fields. Then you can store your data in a PV Array of KeyValue type, which will contain your list nicely. You can always use displayvalue() to get a value for a specific key name, when necessary.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
tmalaher
over 9 years ago
Thanks. The CDT you suggest is exactly what I already have. displayvalue() seems to work nicely to retrieve one field:
displayvalue("FirstName",pv!queryResult.fields.name,pv!queryResult.fields.value,"n/a")
This isn't as efficient as a dictionary, but is much better than using a string-based keyval.
I would rather have done something like:
pv!queryResult.fields.FirstName, but I can wrap the displayvalue() a rule so that I can do:
rule!getQueryResultFieldValue(pv!queryResult,"FirstName")
and this gets me what I want.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 9 years ago
That is a great idea to keep in mind :-)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel