Can anyone explain how to fix this error: Invalid index: Cannot index property 'Status' of type Text into type Text.

Certified Associate Developer

Hi, 

I am having some issues with a!save. When I use the below code and select a data point on the chart the following error occurs:

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error: An error occurred while executing a save: java.lang.IllegalArgumentException: Invalid index: Cannot index property 'Status' of type Text into type Text.

 

{
  with(
    local!chartPagingInfo: a!pagingInfo(
      startIndex: 1,
      batchSize: - 1,
      sort: a!sortInfo(
        field: "SubmittedDate",
        ascending: true
      )
    ),
    local!SubmittedDate: null,
    local!datasubset: a!queryEntity(
      entity: cons!NSARequest_Entity_Cons,
      query: a!query(
        aggregation: a!queryAggregation(
          aggregationColumns: {
            a!queryAggregationColumn(
              field: "Status",
              alias: "Status",
              isGrouping: true
            ),
            a!queryAggregationColumn(
              field: "SubmittedDate",
              alias: "SubmittedDate",
              isGrouping: true,
              groupingFunction: "MONTH"
            ),
            a!queryAggregationColumn(
              field: "Id",
              aggregationFunction: "COUNT"
            )
          }
        ),
        pagingInfo: local!chartPagingInfo
      )
    ),
    local!Categories: index(
      local!datasubset.data,
      "SubmittedDate",
      {}
    ),
    local!uniqueCategories: union(
      local!Categories,cast(typeof(local!Categories),{})
    ),
    local!labels: index(
      local!datasubset.data,
      "Status",
      {}
    ),
    local!uniqueLabels: union(
      local!labels,
      cast(
        typeof(
          local!labels
        ),
        {}
      )
    ),
    local!series: a!forEach(
      local!uniquelabels,
      with(
       local!label: fv!item,
        a!chartSeries(
          label: local!label,
          data: a!forEach(
            local!uniqueCategories,
            with(local!intersection: intersection(
                where(local!Categories = cast(typeof(local!Categories), fv!item),0),
                where(local!labels = cast(typeof(local!labels),local!label), 0)
              ),
              if(condition: length( local!intersection) = 0,
                valueIfTrue: 0,
                valueIfFalse: index(index(local!datasubset.data,"Id",{}),local!intersection,0)
              )
            )
          ),
          links: a!dynamicLink( saveInto: { a!save(ri!selectedStatus, fv!item.Status)}
          )
        )
      )
    ),
    a!lineChartField(
      label: "Number of Assets per Month",
      categories: {
        {
          local!uniqueCategories
        }
      },
      series: local!series,
      xAxisTitle: "Month",
      yAxisTitle: "Number of Assets",
      showDataLabels: true
    )
  ),

Can anyone help?

Thanks

  Discussion posts and replies are publicly visible

  • Try this...a!save(ri!selectedStatus, fv!item)...fv!item does not have the property "Status" because the way you defined local!uniqueCategories.
  • Hi,

    You use below code,

     

    {
      with(
        local!chartPagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: - 1,
          sort: a!sortInfo(
            field: "SubmittedDate",
            ascending: true
          )
        ),
        local!SubmittedDate: null,
        local!datasubset: a!queryEntity(
          entity: cons!NSARequest_Entity_Cons,
          query: a!query(
            aggregation: a!queryAggregation(
              aggregationColumns: {
                a!queryAggregationColumn(
                  field: "Status",
                  alias: "Status",
                  isGrouping: true
                ),
                a!queryAggregationColumn(
                  field: "SubmittedDate",
                  alias: "SubmittedDate",
                  isGrouping: true,
                  groupingFunction: "MONTH"
                ),
                a!queryAggregationColumn(
                  field: "Id",
                  aggregationFunction: "COUNT"
                )
              }
            ),
            pagingInfo: local!chartPagingInfo
          )
        ),
        local!Categories: index(
          local!datasubset.data,
          "SubmittedDate",
          {}
        ),
        local!uniqueCategories: union(
          local!Categories,cast(typeof(local!Categories),{})
        ),
        local!labels: index(
          local!datasubset.data,
          "Status",
          {}
        ),
        local!uniqueLabels: union(
          local!labels,
          cast(
            typeof(
              local!labels
            ),
            {}
          )
        ),
        local!series: a!forEach(
          local!uniquelabels,
          with(
           local!label: fv!item,
            a!chartSeries(
              label: local!label,
              data: a!forEach(
                local!uniqueCategories,
                with(local!intersection: intersection(
                    where(local!Categories = cast(typeof(local!Categories), fv!item),0),
                    where(local!labels = cast(typeof(local!labels),local!label), 0)
                  ),
                  if(condition: length( local!intersection) = 0,
                    valueIfTrue: 0,
                    valueIfFalse: index(index(local!datasubset.data,"Id",{}),local!intersection,0)
                  )
                )
              ),
              links: a!dynamicLink( saveInto: { a!save(ri!selectedStatus, fv!item)}  /* fv!item.Status is not required as fv!item already contains Status only  */
              )
            )
          )
        ),
        a!lineChartField(
          label: "Number of Assets per Month",
          categories: {
            {
              local!uniqueCategories
            }
          },
          series: local!series,
          xAxisTitle: "Month",
          yAxisTitle: "Number of Assets",
          showDataLabels: true
        )
      ),
    
    /*
        local!labels: index(
          local!datasubset.data,
          "Status",
          {}
        ),
        local!uniqueLabels: union(
          local!labels,
          cast(
            typeof(
              local!labels
            ),
            {}
          )
        )
    
     */ 
      /* fv!item.Status is not required as fv!item already contains Status only  */

    /* fv!item.Status is not required as fv!item already contains Status only  */

    Thanks

    Aditya

     

  • Hi ,
    Rather than using dot notation, Do use fn!index in order to find/traverse/get the value from any CDT/Dictionary.
    Thanks
    Madhu
  • 0
    Certified Lead Developer
    Hi Nikin,
    Same code worked for me, when I replaced entity constant with my environment entity.
    So I will suggest to make sure your database table is not empty and your entity is returning value otherwise indexing will not work. If that is the case, please handle null. Thanks