Skip to main content
March 9, 2023
Question

Expression rule to get indistinct details

  • March 9, 2023
  • 4 replies
  • 0 views

Hi,

I have below rule which gives output for distinct values only, but I want get output for indistinct values also.

For Ex: If I give rule input for groupId_int as {496,496,498} , I should get output for all 3 values though it repeats for 496 two times. But here I'm getting only for 2 items as below screen shot.

Can anyone please help me how to approach 

index(
  a!queryEntity_22r2(
    entity: cons!RGRACSLBL_ENTITY_APPIAN_GROUPS,
    query: a!query(
      logicalExpression: a!queryLogicalExpression(
        operator: "AND",
        filters: {
          a!queryFilter(
            field: "Id_int",
            operator: "in",
            value: ri!groupId_int,
            applyWhen: not(
              rule!APN_isBlank(
                ri!groupId_int
              )
            )
          ),
          a!queryFilter(
            field: "groupName_txt",
            operator: "in",
            value: ri!groupName_txt,
            applyWhen: not(
              rule!APN_isBlank(
                ri!groupName_txt
              )
            )
          )
        }
      ),
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: - 1
      )
    )
  ),
  "data",
  {}
)
  

    4 replies

    pragnaj0001
    March 9, 2023

    use a!for each in query filter group_Id. so query will execute each iteration. 

    stefanhelzle0001
    March 9, 2023

    Doing a query in a foreach is a bad practice in terms of performance and memory consumption.

    But, you could fetch the distinct items first, and then use a foreach on the incoming IDs to return the corresponding items.

    abhayd3663
    March 9, 2023

    It seems you are querying based on the result from ri!groupId_int(), and the database table will have only one record for 496 and hence it returned one resultset for 496.  

    March 9, 2023

    As Stefan mentioned, query the distinct data on load and use the onload data to do the foreach on your group ids to get the data for your expected output. Don't do foreach on query itself which causes performance issues.