Rendering different values based on count function

I have a constant that stores three different values. My table has a list of items, where the constant can be either pass, fail, or na. 

I want to have three different sections on a new interface where it will show one section as all items that are in value 1 from the constant. All items that are in value 2 and all that are in value 3. I am not sure exactly how to go about this? 

  Discussion posts and replies are publicly visible

  • The content that the constant holds are statuses. So when an item is in status 1, I want it to count it and give me the total count of items that are only in status 1. Same for the other two statuses. 

  • Hi Jorge, I am not sure how the data in your tables is structured. But you could take a look at the sample code I have posted below and build your interface similarly:

    with(
    local!difficulty: {"HIGH", "MEDIUM", "LOW"},
    local!randomItems: {
    {task: "Build a pyramid", difficulty: "HIGH"},
    {task: "Run a marathon", difficulty: "MEDIUM"},
    {task: "Space travel", difficulty: "HIGH"},
    {task: "Make coffee", difficulty: "LOW"}
    },
    a!forEach(
    local!difficulty,
    a!richTextDisplayField(
    value: {
    with(
    local!indices: wherecontains(tostring(fv!item), touniformstring(local!randomItems.difficulty)),
    {
    a!richTextItem(
    text: length(local!indices)&" "&fv!item&" items:",
    ),
    char(10),
    a!richTextBulletedList(
    items: a!forEach(local!indices,
    a!richTextItem(
    text: index(index(local!randomItems, fv!item, {}), "task", {})
    )
    )
    )
    }
    )
    }
    )
    )
    )

  • +1
    Certified Lead Developer
    in reply to Jorge Arellano

    You would just be replacing local!difficulty with your status constant (or a db query fetching ref data) and local!randomItems with a queryEntity that returns the items from the db.

  • It might be even easier if you have the data coming from a database. You can set up your query to aggregate on the field you want to compare to the constant. Then, you can use wherecontains to find the count of the associated data. Here's an example:

    a!localVariables(
      local!query:a!queryEntity(
        entity: cons!<YOUR ENTITY HERE>,
        query: a!query(
          pagingInfo: a!pagingInfo(
            startIndex: 1,
            batchSize: -1
          ),
          aggregation: a!queryAggregation(
            aggregationColumns: {
              a!queryAggregationColumn(field: "<YOUR FIELD NAME HERE>", isGrouping: true),
              a!queryAggregationColumn(field: "id", aggregationFunction: "COUNT", alias: "count")
            }
          )
        )
      ),
      a!textField(
        label: "Count of Constant Value 1",
        readOnly: true,
        value: index(
          local!query.data.count,
          wherecontains(cons!<YOUR CONSTANT HERE>[1], touniformstring(local!query.data.<YOUR FIELD NAME HERE>)),
          0
        )
      )
    )

    In this example, I group by the field in the database to create the correct count. Then, I find whether that value exists in the output using wherecontains(). I can then find the associated count using the index() function.