Skip to main content
February 21, 2024
Solved

Invalid types, can only act on data of the same type (Any Type, CDT)

  • February 21, 2024
  • 6 replies
  • 0 views

 a!columnChartField(
        label: "Année",
        labelPosition: "JUSTIFIED",
        categories: a!forEach(
          items: local!periodes[local!selectedPeriod].weeks.week,
          expression: "S" & fv!item
        ),
        series: a!forEach(
          items: local!uPerWeekPeriode,
          expression: a!localVariables(
            local!cBrandId: fv!item.cBrandId,
            a!chartSeries(
              label: fv!item.cBrand,
              data: if(
                contains(fv!item.cBrandId, ri!selectedUs),
                fv!item.uPerWeeks,
                {}
              ),
              links: a!forEach(
                items: local!periodes[local!selectedPeriod].weeks,
                expression: a!dynamicLink(
                  saveInto: {
                    a!save(ri!filteredYear,tointeger(fv!item.year)),
                    a!save(ri!filteredWeek,fv!item.week),
                    a!save(ri!filteredStatus,cons!STATUT),
                    a!save(ri!filteredCBrand,local!cBrandId),
                    a!save(ri!displayPList,true)
                  }
                )
              )
            )
          )
        ),
        yAxisMax: local!topAxisUb,
        stacking: "NONE",
        showLegend: true,
        showTooltips: true
      ),

I wanted to filter the chart to display only "selected Us". In othrer words, only contains" selected Us". 

Best answer by stewart.burchell

Yup. So as already mentioned:

"The error itself is simply saying it can't compare two different types of data. You need to cast one (or both) of them to a common data type before they can be compared."

6 replies

dhananjayk3480
February 21, 2024

Can you post the screenshot of chart as well, its hard to imagine?

February 21, 2024

Sorry, the chart doesn't display with this. I don't have chart yet

stewart.burchell
February 21, 2024

Is the error referencing a line number in the code? The error itself is simply saying it can't compare two different types of data. You need to cast one (or both)( of them to a common data type before they can be compared. Since you mention 'selected Us' my guess is the error is in Line 15 in your code block above.

February 21, 2024

line number 15  at function 'contains' [line 15]: Invalid types, can only act on data of the same type (Any Type, Type CDT)

stewart.burchell
February 21, 2024

Yup. So as already mentioned:

"The error itself is simply saying it can't compare two different types of data. You need to cast one (or both) of them to a common data type before they can be compared."

santhoshr9843
February 22, 2024

As a best practice, whenever you are using comparision functions like contains() and wherecontains() always typecast them. Especially when you are dealing with local variables because they wont have any datatype by default. In the above case, you can rewrite the above contains logic like this (assuming they are integers):

contains(

tointeger(index(fv!item, "cBrandId", "")),

tointeger(ri!selectedUs)