Skip to main content
Known Participant
Sep 30, 2021 11:57 PM UTC
Solved

only getting last item from query

...
local!cart: rule!AS_Get_Cart(),
...
a!gridLayout(
        label: "Editable Grid",
        labelPosition: "COLLAPSED",
        headerCells: {
          a!gridLayoutHeaderCell(label: "Item"),
          a!gridLayoutHeaderCell(
            label: "Price"
          ),
          a!gridLayoutHeaderCell(
            label: "Stock"
          ),
          a!gridLayoutHeaderCell(
            label: "Quantity",
            helpTooltip: "The number of items you want to buy"
          ),
          a!gridLayoutHeaderCell(
            label: "Total Price"
          ),
          a!gridLayoutHeaderCell(
            label: ""
          )
        },
        columnConfigs: {
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 4
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 1
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE"
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE"
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE"
          ),
          a!gridLayoutColumnConfig(
            width: "ICON"
          )
        },
        rows: {
          {
            a!forEach(
              items: local!cart,
              expression: a!gridRowLayout(
            contents: {
              a!textField(
                label: "item",
                labelPosition: "ABOVE",
                value: fv!item.name,
                saveInto: {},
                refreshAfter: "UNFOCUS",
                readOnly: true,
                validations: {}
              ),
              a!floatingPointField(
                label: "price",
                labelPosition: "ABOVE",
                value: fv!item.price,
                saveInto: {},
                refreshAfter: "UNFOCUS",
                readOnly: true,
                validations: {}
              ),
              a!integerField(
                label: "stock",
                labelPosition: "ABOVE",
                value: fv!item.stock,
                saveInto: {},
                refreshAfter: "UNFOCUS",
                readOnly: true,
                validations: {}
              ),
              a!integerField(
                label: "quantity",
                labelPosition: "ABOVE",
                value: fv!item.quantity,
                saveInto: fv!item.quantity,
                refreshAfter: "UNFOCUS",
                required: true,
                validations: if(fv!item.quantity>fv!item.stock,"Sorry, we dont have those many items in stock",null())
              ),
              a!floatingPointField(
                label: "TotalPrice",
                labelPosition: "ABOVE",
                value: if(isnull(fv!item.quantity),"$0",dollar(tointeger(fv!item.quantity) * todecimal(fv!item.price))),
                saveInto: fv!item.total,
                refreshAfter: "UNFOCUS",
                validations: {}
              ),
              a!richTextDisplayField(
                labelPosition: "COLLAPSED",
                value: {
                  a!richTextIcon(
                    icon: "times",
                    link: a!dynamicLink(
                      label: "Dynamic Link",
                      saveInto: {
                        a!deleteFromDataStoreEntities(dataToDelete: a!entityDataIdentifiers(
                          entity: cons!AS_DataStore_Cart_Pointer,
                          identifiers: fv!item.name
                        ))
                      }
                    ),
                    color: "#ff0000"
                  )
                }
              )
            }
              ))

a!localVariables(
  local!results:
  a!queryEntity(
  entity: cons!AS_DataStore_Cart_Pointer,
  query: a!query(
    pagingInfo: a!pagingInfo(
      startIndex: 1,
      batchSize: 50
    )
  ),
  fetchTotalCount: false
).data,
cast(typeof('type!{urn:appian:as}AS_Cart_DataBase'()),
local!results))

So, I have this query and this snippet but the grid is only displaying the last item introduced in my DB, any hint in whats wrong?

    acaciob0002
    Participating Frequently
    Oct 1, 2021 12:13 AM UTC

    Well using the refreshVariable you have few different ways to refresh your variable (refreshAlways, refreshOnReferencedVarChange, refreshOnVarChange, refreshAfter) depend of what are you trying to achieve 

    6 replies

    acaciob0002
    Participating Frequently
    Oct 1, 2021 12:08 AM UTC

    Hi [mention:f9aba0930c5d41b98630cf9a39c51b01:e9ed411860ed4f2ba0265705b8793d05],

    How many items that you can see in your local!cart?

    Regards,

    Acacio B.

    Known Participant
    Oct 1, 2021 12:09 AM UTC

    Got it, was missing some curly braces covering the type! 

    Known Participant
    Oct 1, 2021 12:10 AM UTC

    since you're here, do you know of any way I can refresh a variable without using some time event? like on the click of a button