Hello everyone.
I want to retrieve the key field in the dictionary(queried from cdt) based on the value present.
I have the data set in following order.
txt1 112 (Number (Decimal))
txt2 113 (Number (Decimal))
txt3 114 (Number (Decimal))
txt4 115 (Number (Decimal))
Input: 115
expected output: txt4
Please help me in getting the answer.
Discussion posts and replies are publicly visible
a!localVariables( local!dictionary: { txt1: 112, txt2: 113, txt3: 114, txt4: 115 }, reject( fn!isnull, a!forEach( items: a!keys(local!dictionary), expression: a!localVariables( local!value: todecimal(index(local!dictionary, fv!item, null)), if(local!value = ri!input, fv!item, null) ) ) ) )
Hello Mathieu Drouin,
Here dictionary is the output from the query entity.
a!keys will through the following error.
Expression evaluation error at function a!keys [line 44]: The passed parameter(s) are of the wrong type. Received the type List of Variant.
Here's a version that takes the dictionary as an input and casts it to a map.
reject( fn!isnull, a!forEach( items: a!keys(cast(typeof(a!map()), ri!dictionary)), expression: a!localVariables( local!value: todecimal(index(ri!dictionary, fv!item, null)), if(local!value = ri!input, fv!item, null) ) ) )
a!localVariables( local!dictionary:{ txt1:112, txt2:113, txt3:114, txt4:115 }, a!forEach( items:a!keys(local!dictionary), expression: a!localVariables( if( todecimal(index(local!dictionary, fv!item,null))=ri!input, fv!item, {} ) ) ) )