Refresh grid with data from recorType after record deletion

Certified Lead Developer

Hi all,

Here are my needs:

I have a grid of records with checkboxes and a button. I woud like to delete selected records and refresh the grid.

Deletion works good. Refresh does not work.

I read alreqy these 3 posts with problems similas to mine,  without finding a solution:

What i did so far is to create a read only grid. Data are retriven from a recordType, relying directly from the DS. 

Clicking on checkboxes stores record ids on a local variable.

The button invokes a PM who does other operations before deleting checked records from DS.

All branches in PM are chained up to the delete step.

here the button:

    a!buttonWidget(
              label: "Delete",
              icon: "trash",
              saveInto: {
                a!startProcess(
                  processModel: cons!PM_deleteRequests,
                  processParameters: {
                    requestsToBeDeleted: local!selectedRequests
                  },
                  onSuccess: {
                    a!save(local!succes, local!succes + 1),
                    a!save(local!selectedRequests, null())
                  },
                  onError: a!save(local!error, true())
                )

Here are the parameters:

         selectable: true,
          selectionStyle: "CHECKBOX",
          selectionValue: local!selectedRequests,
          selectionSaveInto: local!selectedRequests,
          validations: {},
          spacing: "DENSE",
          height: "AUTO",
          borderStyle: "STANDARD",
          refreshAlways: false,
          refreshAfter: "RECORD_ACTION",
          refreshOnVarChange: local!succes,
    /* I tried these last 3 param each one alone and in combination*/
          showSearchBox: false,
          showRefreshButton: false,
          recordActions: {}
        )
 

here how a field in the grid is invoked:

            a!gridColumn(
              label: "Document Title",
              sortField: 'recordType!Request.fields.{documentTitle}documentTitle',
              value: fv!row['recordType!Request.fields.{documentTitle}documentTitle'],
              align: "START"
            ),

Any hint/help is welcome

Thanks A lot

Ale

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    The automatic refresh works for record action fields only. You will have to refresh the data manually. I typically add a local called "refreshCounter", then fetch the data for the grid an a local variable which is then refreshed if that counter is incremented. Feed that locally stored data to the data attribute of the grid.

  • Have you tried Refresh After parameter in Read Only Grid, if you have given delete action as a record action you can use this parameter available in a!gridField() 

  • 0
    Certified Lead Developer
    in reply to Stefan Helzle

    I tried to spool the query in the local!data variable at the beginning.

      local!datarefresh: 0,
      local!data: a!refreshVariable(
      value: a!recordData(
        recordType: 'recordType Request',
        filters: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: 'recordType Request.fields.{endDate}endDate',
              operator: "is null"
            ),
            a!queryFilter(
              field: 'recordType! Request.fields.{active}active',
              operator: "=",
              value: true
            )
          },
          ignoreFiltersWithEmptyValues: true
        )
      ),
     refreshOnVarChange: local!datarefresh
      ),

    Then into the button, on succes i increase local!datarefresh variable to arrange an update

     a!startProcess(
                      processModel: cons!PM_deleteRequests,
                      processParameters: {
                        requestsToBeDeleted: local!selectedRequests
                      },
                      onSuccess: {
                        a!save(local!datarefresh, local!datarefresh + 1),
                        a!save(local!selectedRequests, null())
                      },
                      onError: a!save(local!error, true())
                    )

    The in the grid, i fetch local!data as data:

     a!gridField(
              data: local!data,
              columns: ...
              initialSorts:...
              secondarySorts:..
                selectable: true,
              selectionStyle: "CHECKBOX",
              selectionValue: local!selectedRequests,
              selectionSaveInto: local!selectedRequests,
              validations: {},
              spacing: "DENSE",
              height: "AUTO",
              borderStyle: "STANDARD",
              /*refreshAlways: true(),*/
              refreshOnVarChange: local!datarefresh,
              /*refreshAfter: "RECORD_ACTION",*/
        /*the 3 options above had been tested in any possible combination*/
              showSearchBox: false,
              showRefreshButton: false,
              recordActions: {}
            )
          },

    No way, refresh does not happen.

    What's wrong?

    thanks a lot

  • 0
    Certified Lead Developer
    in reply to Geetha Satya Sree

    No way to make it work with refresh after: "RECORD_ACTION".

    Either in the read-only box or in a!refreshvariable() function.

  • 0
    Certified Lead Developer
    in reply to Alessandro M.

    This setup looks correct from an initial skim-through.  The one thing you'll need to double-check (which you haven't provided either way here) is that your process has chaining enabled all the way through to the node that performs the "deletion" in the database.  The "onSuccess" save will execute *immediately* upon the first chaining break in the process, and if, for example, you have no chaining set up in the process, it would be happening way too early to be properly caught by your refresh variable setup seen here.

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    Hi Mike,

    Thanks for your reply.

    yes, steps in the PM workflow are chained as you can see in the attached pic:

    Btw, I also tried by using QueryEntity instead of recordType. Same options, no refresh.

  • 0
    Certified Lead Developer
    in reply to Alessandro M.

    Gotcha, thanks for confirming.  Another thing you should watch is to make sure your refresh counter is actually incrementing when the form action is done.  And if so, one way you can brute-force test the behavior is to make a *manual* edit directly to the DB data, then force-increment the refresh counter by itself (like via a separate debug-only button/link), and see if you can get the local data to refresh.  The point here is to narrow down where the disconnect is happening.

  • +1
    Certified Lead Developer

    I do reply to my own message to explain how I solved this problem.

    The recordType I was using (and so far the only one relying on the DB table of my interest) was of type Data Store Entity.

    I created a new RecordType, from wizard I chose to keep the syncronization and then the type was Database.

    I created then a new interface from scratch using this new object but, the data parameter in the grid was just a recordtype.

    The grid has the parameter refreshOnVarChange: local!success and this local variable is updated each time the user clicks on my custom delete button. 

    The process model did not change.

    Thanks to ,  and for hints and help.