QueryRecord

Certified Senior Developer

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",
    {}
  )
)

This is the error I am getting.
Expression evaluation error at function a!queryRecordType [line 25]: Invalid record field type mapping. No matching ADS type for appianTypeId: 252.

Thanks in Advance.

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Are you sure that this is worth the effort? I mean, this is what a!queryRecordType() is doing already.

  • 0
    Certified Senior Developer

    Hello   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.

  • 0
    Certified Senior Developer

    HI  ,

    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

  • 0
    Certified Senior Developer

    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",
        {}
      )