Convert Local Variable to Array

Certified Associate Developer

Hello, 

I am using local variable as a filter for a query: 

a!queryFilter(
field: "codigoMunicipio",
operator: "IN",
value: local!municipioMultiple
)

Problem is tha the variable is passed as String and the filter have condition IN 

Which generates the following error: 

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error in rule 'tax_colopoc' at function a!gridField [line 310]: Cannot apply operator [IN] to field [importMonth] when comparing to value [TypedValue[it=3,v=January]].

Any idea how to pass it as an array {"January"} ?

  Discussion posts and replies are publicly visible

  • Hi Vladmir - Pass your value argument in {} braces. That should hopefully solve your issue.

    a!queryFilter(
    field: "codigoMunicipio",
    operator: "IN",
    value: {local!municipioMultiple}
    )

  • 0
    Certified Associate Developer
    in reply to Siddharth

    Hello Siddharth, 

    I have applied this change but there is no difference. Still showing the same error. 

  • Can you please paste the contents of your expression so that it would be easier to debug the error.

  • 0
    Certified Associate Developer
    in reply to Siddharth

    Here is the whole Expression

    a!localVariables(
      local!municipioMultiple,
      local!municipioMultipleNoGravable,
      local!searchMonth,
      local!searchMonthNoGravable,
      local!searchYear,
      local!searchYearNoGravable,
      local!municipio,
      local!municipioNoGravable,
      local!saveData,
      local!municipios: rule!TAX_ColoPOC_Municipio_Names(),
      local!importesNoGravables: rule!TAX_ColoPOC_GetAllImportesNoGravables(),
      a!formLayout(
        label: "",
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!imageField(
                    label: "",
                    labelPosition: "ABOVE",
                    images: {
                      a!documentImage(
                        document: cons!CONS_HEADER_IMAGE
                      )
                    },
                    size: "FIT",
                    isThumbnail: false,
                    style: "STANDARD",
                    align: "CENTER"
                  )
                }
              )
            }
          ),
          rule!FPKB_SectionHeader(
            icon: "file-o",
            highlightText: "Reporte",
            secondaryText: "Provisiones"
          ),
          a!sectionLayout(
            label: "TITLE",
            contents: {
              a!columnsLayout(
                columns: {
                  a!columnLayout(
                    contents: {
                      a!multipleDropdownField(
                        label: "Month",
                        labelPosition: "ABOVE",
                        placeholder: "--- Seleccionar Mes ---",
                        choiceLabels: {
                          "January",
                          "February",
                          "March"                  
                        },
                        choiceValues: {
                        "January",
                          "February",
                          "March"                    
                        },
                        value: local!searchMonth,
                        saveInto: local!searchMonth,
                        validations: {}
                      )
                    }
                  ),
                  a!columnLayout(
                    contents: {
                      a!textField(
                        label: "Año",
                        labelPosition: "ABOVE",
                        value: local!searchYear,
                        saveInto: local!searchYear,
                        refreshAfter: "UNFOCUS",
                        validations: {}
                      )
                    }
                  ),
                  a!columnLayout(
                    contents: {
                      a!multipleDropdownField(
                        label: "Municipio",
                        labelPosition: "ABOVE",
                        placeholder: "--- Seleccionar Municipio ---",
                        choiceLabels: index(
                          local!municipios,
                          "poblacion"
                        ),
                        choiceValues: index(
                          local!municipios,
                          "zip"
                        ),
                        value: local!municipioMultiple,
                        saveInto: local!municipioMultiple,
                        showwhen: true,
                        validations: {}
                      )
                    }
                  )
                }
              ),
              a!gridField(
                label: "",
                labelPosition: "ABOVE",
                data: a!queryEntity(
                  entity: cons!CONS_ENTITY_POINTER_INGRESOS_GRAVABLES,
                  query: a!query(
                    aggregation: a!queryAggregation(
                      aggregationColumns: {
                        a!queryAggregationColumn(
                          field: "codigoMunicipio",
                          isGrouping: true
                        ),
                        a!queryAggregationColumn(
                          field: "descripcionMunicipio",
                          isGrouping: true
                        ),
                        a!queryAggregationColumn(
                          field: "importeDocumento",
                          alias: "importeDocumento_sum",
                          aggregationFunction: "SUM"
                        ),
                        a!queryAggregationColumn(
                          field: "tarifaICA",
                          alias: "tarifaICA_sum",
                          aggregationFunction: "SUM"
                        ),
                        a!queryAggregationColumn(
                          field: "tarifaBomberil",
                          alias: "tarifaBomberil_sum",
                          aggregationFunction: "SUM"
                        ),
                        a!queryAggregationColumn(
                          field: "tarifaAvisosYTableros",
                          alias: "tarifaAvisosYTableros_sum",
                          aggregationFunction: "SUM"
                        )
                      }
                    ),
                    logicalExpression: a!queryLogicalExpression(
                      operator: "AND",
                      filters: {
                        a!queryFilter(
                          field: "importMonth",
                          operator: "IN",
                          value: touniformstring (local!searchMonth)
                        ),
                        a!queryFilter(
                          field: "importYear",
                          operator: "=",
                          value: local!searchYear
                        ),
                        a!queryFilter(
                          field: "codigoMunicipio",
                          operator: "IN",
                          value: local!municipioMultiple
                        )
                      },
                      ignoreFiltersWithEmptyValues: true
                    ),
                    pagingInfo: fv!pagingInfo
                  ),
                  fetchTotalCount: true
                ),
                columns: {
                  a!gridColumn(
                    label: "Codigo Municipio",
                    sortField: "codigoMunicipio",
                    value: fv!row.codigoMunicipio
                  ),
                  a!gridColumn(
                    label: "Municipio",
                    sortField: "descripcionMunicipio",
                    value: fv!row.descripcionMunicipio
                  ),
                  a!gridColumn(
                    label: "Importe Gravable",
                    sortField: "importeDocumento_sum",
                    value: dollar(
                      fv!row.importeDocumento_sum
                    )
                  ),
                  a!gridColumn(
                    label: "Importe ICA",
                    sortField: "tarifaICA_sum",
                    value: dollar(
                      fv!row.tarifaICA_sum
                    )
                  ),
                  a!gridColumn(
                    label: "Importe Bomberil",
                    sortField: "tarifaBomberil_sum",
                    value: dollar(
                      fv!row.tarifaBomberil_sum
                    )
                  ),
                  a!gridColumn(
                    label: "Importe Avisos Y Tableros",
                    sortField: "tarifaAvisosYTableros_sum",
                    value: dollar(
                      fv!row.tarifaAvisosYTableros_sum
                    )
                  )
                },
                validations: {}
              )
            }
          )        
        }
      )
    )

  • Looking like it is a type casting issue, try like this for once

    a!queryFilter(
    field: "codigoMunicipio",
    operator: "IN",
    value: {

    touniformstring(

    local!municipioMultiple

    )
    }
    )

  • 0
    Certified Associate Developer
    in reply to ankita0004

    Hello Ankit, 

    Thank you for your answer. I have tried it and receiving the same error. 

  • Hi, Can you send me the complete query entity code with related xsd code?

  • 0
    Certified Associate Developer
    in reply to ankita0004

    I have updated the whole code in the previous reply. 

    attaching here the CDT 

  • 0
    Certified Lead Developer
    in reply to Vladimir Vasilev

    Are you seeing the error immediately upon trying to load the interface?  If so, then my first guess is that since you're initializing local!municipioMultiple with no value, this is resulting in it having a non-multiple "null" value, which the query wouldn't like.  So the first and easiest thing I'd suggest you change is in your variable definition, set the initial value like:

    local!municipioMultiple: {},

    Also, you will probably need to do this conversion for local!searchMonth also, since that seems to be the one your error message is actually complaining about.  And any other local variables that are passed into the query with the assumption that they're an array (though from a quick scan of your code, it appears those might be the only two).

    As a side note: a good practice in general is to create an Expression Rule to handle any Query Entity which might be used in more than one place in the system.  They can be set up to be flexible and easily handle multiple different use cases with multiple different assumed input sets, with little to no extra effort.  I bring this up mainly because if you had done this for yours already, you likely wouldn't be having the error you're getting, due to the fact that you would have had to type cast these two filter variables as "array" type in the Rule Inputs of the expression rule, and therefore they'd manually typecast even a blank non-array incoming string as an empty set, and not break the query when doing the initial page load with no filter data set.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Hello Mike, 

    I was getting the error when the interface load when I was using Rule Imputs saying that the rull input does not have value. This is why I have changed it to local variables. Now I get the error when I change the drop down filter example when I choose January for example this is when the error is happening. It's like the choosen value can't be passed to the "IN" query filter.