Hi,
I am parcticing with the a!queryRecordType() function and I realized in return one field called identifiers where the primiary key is returned and I would like to know if I could transform it together with the data field into a map where the identifiers values are the keys and the data values are the values.
For example:
Having:
identifiers : {12,20}
data : {"first value", "second value"}
Transform it into
{12: "first value",
20: "second value}
Discussion posts and replies are publicly visible
Hello antoniochl,
Please refer the below code. I hope this will help.
a!localVariables( local!identifiers: { 12, 20 }, local!data: { "first value", "second value" }, { append( a!forEach( items: local!identifiers, expression: concat( fv!item, ": ", index(local!data, fv!index, null) ) ) ) } )
can you also try this,
a!localVariables( local!identifiers: { 12, 20 }, local!data: { "first value", "second value" }, { a!flatten( a!forEach( items: local!identifiers, expression: { a!map( identifier:fv!item, data:index(local!data,fv!index,null) ) } ) ) } )
thank you for your answer, it´s almost what I want but it returns a List of Map and I would like a single Map containing all the data is there any posibilitiy to join them.
Thanks again.
It is possible to do this but it's a rather non-standard scenario. What are you trying to achieve by creating this map?
I'm making a process model where I get an ID and I have to look up in the result of an a!queryRecordType() that I had already saved in an array and I thought the fastest way to do it was to make a map instead of an array where the key were the ID I'm looking for.
In this way you would duplicate the data you already have into another process variable. That is not memory efficient.
Alternative to your solution you could:
- Create an expression that returns the requested value based on rule inpuds: 1/ given id and 2/ data array (originating from your a!queryRecordType()).
- Just query single item on given ID. Create seperate expression rule and set as script task data output in your PM.
Both produce re-usable components that make sense when building an Appian application.
If you have the Dictionary Manipulation plugin:
a!localVariables( local!identifiers:{12,20}, local!data:{"first value","second value"}, a!flatten( a!forEach( items: local!identifiers, expression: cast(typeof({a!map()}),createdictionary(fv!item,local!data[fv!index])) ) ) )
That still gets you a list of maps, though. If you want them in a single text, you can joinarray(a!flatten...,",")
Here's a way to do it that doesn't require the Dictionary Manipulation plugin. Note that the keys cannot key integers, they need to be Strings (hence the cast).
a!localVariables( local!keys: { 12, 20 }, local!values: { "first value", "second value" }, local!keyValues: a!forEach( items: local!keys, expression: a!map( key: fv!item, value: index(local!values, fv!index, null) ) ), a!update( a!map(), cast(typeof({ "" }), local!keyValues.key), local!keyValues.value ) )