Hi All I am trying to design a generic rule which will take recordtype. filter fields and filter values and filter operators and final filed as inputs and it should give result of that final field after ruining the query Record and applying the aggregation.It is working if the filter are single or multiple and all filter operators are "=","<>","<",">" but not when filters are multiple and operators are mix of in ,= or not in,= .here is the code i have used.
a!localVariables( local!filterFields: { recordFields }, local!filterValues: { a!update(a!map(), "1", { 21, 27 }), true() }, local!filterOperators: { "in", "=" }, index( a!queryRecordType( recordType: recordName, fields: finalOutputField, filters: a!queryLogicalExpression( operator: "AND", filters: a!forEach( items: { local!filterFields }, expression: a!queryFilter( field: fv!item, operator: local!filterOperators[fv!index], value: if( contains( { "in", "not in" }, local!filterOperators[fv!index][1] ), a!localVariables( local!indexData: local!filterValues[fv!index][1], if( a!isNullOrEmpty(local!indexData), local!filterValues[touniformstring(fv!index)][1], local!indexData ) ), local!filterValues[fv!index] ) ) ), ignoreFiltersWithEmptyValues: true ), fetchTotalCount: true(), pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 0) ), "totalCount", {} ) )
Discussion posts and replies are publicly visible
Are you sure that this is worth the effort? I mean, this is what a!queryRecordType() is doing already.
Hello Ramesh Palati I understand your requirement but having a hard time to understand the expression at the filters. But coming to your error it must be related to the type mismatch while casting your record type. This implementation can fail at any point if any slight mismatch of input occurs. So, I would recommend using different expressions for querying individual record type.
HI Ramesh Palati ,
I think there is an issue in your code line no: 19 local!filterOperators[fv!index][1] returns 'i' or '=' remove [1] and try again.
In line no : 22,25 trying to index with integer as you have map with 1 as string try placeing the ["1"] like tihs .Hope this will sort your issue
Thanks All,Found the issue and able to fix it.
index( a!queryRecordType( recordType: ri!record, fields: ri!finalField, filters: a!queryLogicalExpression( operator: "AND", filters: if( a!isNullOrEmpty(ri!filterFields), {}, a!forEach( items: ri!filterFields, expression: a!queryFilter( field: fv!item, operator: ri!filterOperators[fv!index], value: if( contains( { "in", "not in" }, ri!filterOperators[fv!index] ), a!localVariables( local!indexData: index(ri!filterValues[fv!index], fv!index, {}), if( a!isNullOrEmpty(local!indexData), index( ri!filterValues[fv!index], touniformstring(fv!index), {} ), local!indexData ) ), index( ri!filterValues[fv!index], touniformstring(fv!index), {} ) ), ) ) ), ignoreFiltersWithEmptyValues: true ), fetchTotalCount: true(), pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 0) ), "totalCount", {} )