Skip to main content
December 2, 2021
Question

How to remove null from a list returned by query entitiy

  • December 2, 2021
  • 1 reply
  • 1 view

Hi I have this code written

local!productgroup: a!queryEntity(
    entity: cons!MPPCONSCDT_megaMasterFile,
    query: a!query(
      /*selection: a!querySelection(*/
      /*columns: {*/
      /*a!queryColumn(*/
      /*field: "productline",*/
      /*alias: "productline",*/
      /*             */
      /*)*/
      /*}*/
      /*),*/
      aggregation: a!queryAggregation(
        aggregationColumns: {
          a!queryAggregationColumn(
            field: "EOMYear",
            alias: "EOMYear",
            isGrouping: true()
          )
        }
      ),
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: -1
      )
    ),
    fetchTotalCount: true
  ).data,

I returns below result

Is there any way I can remove the null one?

    1 reply

    stewart.burchell
    December 2, 2021

    You have a couple of choices:

    • you can add a filter to your queryEntity to exclude all items where 'EOMYear' is null (this is probably the preferred way)
    • you can post-process your list to remove any null entries using fn!reject() - see example code below:

    a!localVariables(
      local!myList: { 1, 2, 3, null, 4, 5 },
      fn!reject(fn!isnull, local!myList)
    )