In order to make a general purpose sub-process to do some lookups in an external

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

Parents
  • 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.
Reply
  • 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.
Children
No Data