How to refresh dynamically a RecordType inside in an interface?

Certified Senior Developer

Hi,

Could you tell me how a filtered RecordType grid (placed inside an interface) can be refreshed please ?

My RecordType data are retrieved from the a!recordData() function, and is filtered on the field "deleted" (all rows are visible if delete = "false").

I have a button that calls an Expression Rule to update the underlying table to set the "deleted" field of the selected row to "true".

(I use the WriteToDataStoreEntity Smartservice).

After the table is updated in database, I have click to click on the "refresh" icon of the RecordType to see that all is working fine : the lines are hidded.

How would you refresh the RecordType, without a manual user action please ?

(I intentionnaly do not use any process model for this example)

  Discussion posts and replies are publicly visible

  • the best solution I can think is to use a local variable that refreshes

  • 0
    Certified Senior Developer
    in reply to ManuelHTG

    Thank you Manuel for your reply, but  a!recordData() is set to a local variable.

    But while this local variable is refreshed (with refreshvariable function), the RecordType is never refreshed.

    Am I missing something ?

  • 0
    Certified Lead Developer
    in reply to cedric01

    Could you post some of your SAIL code?  I would just ask that you use a code box:

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

      local!data: a!recordData(
    	  recordType: 'recordType!vehicles',
    	  filters: a!queryLogicalExpression(
    		operator: "AND",
    		filters: {
    		  a!queryFilter(
    			field: 'recordType!vehicles.fields.deleted',
    			operator: "=",
    			value: false
    		  ),
    		},
    		ignoreFiltersWithEmptyValues: true
    	  )
      ),
    	
      a!gridField(
    	label: "",
    	data: local!data,
    	columns: {
    		...
    	}
    
    
    /* I have tried this too : */
    
      local!data: a!refreshVariable(
        value: a!recordData(
    	  recordType: 'recordType!vehicles',
    	  filters: a!queryLogicalExpression(
    		operator: "AND",
    		filters: {
    		  a!queryFilter(
    			field: 'recordType!vehicles.fields.deleted',
    			operator: "=",
    			value: false
    		  ),
    		},
    		ignoreFiltersWithEmptyValues: true
    	  )
        ),
        refreshOnReferencedVarChange: true,
        refreshOnVarChange: ri!selectedvehicle.deleted
      ),

  • 0
    Certified Lead Developer
    in reply to cedric01

    Can i see the code you're using for the write to data store entity, and/or where the value of ri!selectedVehicle is changed?  (though it sounds like both things are happening in the same-ish place)

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    I'm setting the RI, just before to save data :

    a!buttonArrayLayout(
    	buttons: {
    	  a!buttonWidget(
    		label: "",
    		icon: "arrow-right",
    		saveInto: {
    		  a!save(ri!selectedvehicle.deleted, true),
    		  rule!VH_SaveVehicle(ri!selectedvehicle)
    		},
    	  )
    	},
    )
    
    ER for the saving data : VH_SaveVehicle
    
    a!writeToDataStoreEntity(
      dataStoreEntity: cons!VH_ENTITY_VEHICLE,
      valueToStore: ri!selectedvehicle
    ),

  • 0
    Certified Lead Developer
    in reply to cedric01

    Sorry for the late reply  - Community doesn't see fit to notify me that you've replied to me for some reason.  Anyway.  I usually use a special local variable to update at the end of a data change (by utilizing the onSuccess parameter of the WTDS rule), which then causes subsequent variable values to be refreshed.  This can slot straight into your code -- I haven't used a!recordData as much, so I'm making a little bit of an assumption that it'll work the same way here.

    /* make the following changes to your form local variables: */
      local!refreshCounter: 0,
      local!data: a!refreshVariable(
        value: a!recordData(
          recordType: 'recordType!vehicles',
          filters: a!queryLogicalExpression(
            operator: "AND",
            filters: {
              a!queryFilter(
                field: 'recordType!vehicles.fields.deleted',
                operator: "=",
                value: false
              ),
            },
            ignoreFiltersWithEmptyValues: true
          )
        ),
        refreshOnReferencedVarChange: true,
        refreshOnVarChange: {
          /* ri!selectedvehicle.deleted */
          local!refreshCounter
        }
      ),
    
    /* then one small change to your helper rule call (or, if it's used in other places and you don't want to risk new changes, just perform the WTDS action here until you can tell whether it'll work for you) */
    a!buttonArrayLayout(
      buttons: {
        a!buttonWidget(
          label: "",
          icon: "arrow-right",
          saveInto: {
            a!save(ri!selectedvehicle.deleted, true),
            rule!VH_SaveVehicle(
              selectedVehicle: ri!selectedvehicle,
              refreshCounter: local!refreshCounter /* Added */
            )
          }
        )
      },
    )
    
    /* Then the change within the helper rule itself */
    a!writeToDataStoreEntity(
      dataStoreEntity: cons!VH_ENTITY_VEHICLE,
      valueToStore: ri!selectedvehicle,
      onSuccess: {
        a!save(
          ri!refreshCounter, /* integer */
          ri!refreshCounter + 1
        )
      }
    ),

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Thank you Mike, I have tested with the new local variable but unfortunately, it does not work. (but the variable refreshCounter is well incremented when the onSuccess event occurs in the ER).

    Maybe you're right, it is the a!recordData that is the problem ?

    Would you have any other idea or workaround ?

  • 0
    Certified Lead Developer
    in reply to cedric01

    that might be it, but just in case, could you post a current representative sample of your code?  What happens if you try basically the same setup but using data you get from a queryEntity rule?

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Mike, I can share you the full code, is it what you need ?

    For your suggestion, I'm afraid I can't use anything else than a!recordData, as queryEntity is not compatible with a RecordType. 

    a!localVariables(
      local!selectedRows,
      local!selection,
      local!refreshCounter: 0,
      
      local!data: a!refreshVariable(
        value: a!recordData(
          recordType:'recordType!CJT_R_Vehicles',
          filters: a!queryLogicalExpression(
            operator: "AND",
            filters: {
              a!queryFilter(
                field: 'recordType!CJT_R_Vehicles.fields.deleted',
                operator: "=",
                value: false
              ),
            },
            ignoreFiltersWithEmptyValues: true
          )
        ),
        refreshOnReferencedVarChange: true,
        refreshOnVarChange: {
          local!refreshCounter
        }
      ),
    
      a!formLayout(
        label: "Grid with RecordType",
        contents: {
          a!gridField(
            label: "Vehicles",
            labelPosition: "COLLAPSED",
            data: local!data,
            columns: {
              a!gridColumn(
                label: "Id",
                sortField: 'recordType!CJT_R_Vehicles.fields.id',
                value: fv!row['recordType!CJT_R_Vehicles.fields.id'],
                align: "END"
              ),
              a!gridColumn(
                label: "Make",
                sortField: 'recordType!CJT_R_Vehicles.fields.make',
                value: a!linkField(
                  links: {
                    a!recordLink(
                      label: fv!row['recordType!CJT_R_Vehicles.fields.make'],
                      recordType: 'recordType!CJT_R_Vehicles',
                      identifier: fv!identifier
                    )
                  }
                )
              ),
              a!gridColumn(
                label: "Model",
                sortField: 'recordType!CJT_R_Vehicles.fields.model',
                value: fv!row['recordType!CJT_R_Vehicles.fields.model']
              ),
              a!gridColumn(
                label: "Vin",
                sortField: 'recordType!CJT_R_Vehicles.fields.vin',
                value: fv!row['recordType!CJT_R_Vehicles.fields.vin']
              ),
              a!gridColumn(
                label: "Isavailable",
                sortField: 'recordType!CJT_R_Vehicles.fields.isavailable',
                value: fv!row['recordType!CJT_R_Vehicles.fields.isavailable']
              ),
              a!gridColumn(
                label: "Dateacquired",
                sortField: 'recordType!CJT_R_Vehicles.fields.dateacquired',
                value: fv!row['recordType!CJT_R_Vehicles.fields.dateacquired'],
                align: "END"
              ),
              a!gridColumn(
                label: "Year",
                sortField: 'recordType!CJT_R_Vehicles.fields.year',
                value: fv!row['recordType!CJT_R_Vehicles.fields.year'],
                align: "END"
              ),
              a!gridColumn(
                label: "Deleted",
                sortField: 'recordType!CJT_R_Vehicles.fields.deleted',
                value: fv!row['recordType!CJT_R_Vehicles.fields.deleted']
                align: "END"
              )
            },
    
            initialSorts: {
              a!sortInfo(
                field: 'recordType!CJT_R_Vehicles.fields.id'
              )
            },
            showWhen: true,
            selectable: true,
            selectionStyle: "ROW_HIGHLIGHT",
            selectionValue: local!selection,
            
            selectionsaveInto: {
              a!save(local!selectedRows, index(fv!selectedRows, length(fv!selectedRows), null)),
              a!save(local!selection, index(save!value, length(save!value), null)),
              a!save(ri!selectedVehicle,
                index(
                  fv!selectedRows,
                  length(fv!selectedRows),
                  null
                )
              )
            },
            validations: {},
            refreshAfter: "RECORD_ACTION",
            userFilters: {
            },
            showSearchBox: true,
            showRefreshButton: true,
            showExportButton: false,
            recordActions: {}
          )
        },
        buttons: a!buttonLayout(
          secondaryButtons: {
            a!buttonWidget(
              label: "Delete selected",
              saveInto: {
                a!save(
                  ri!selectedVehicle.deleted, true
                ),
                rule!CJT_ER_SaveVehicle(
                  vehicle: ri!selectedVehicle,
                  refreshCounter: local!refreshCounter
                )
              },
              submit: false,
              style: "PRIMARY",
              showWhen: true,
              confirmMessage: "Do you confirm deactivating this row?",
              disabled: rule!SHARED_IsNullOrEmpty(ri!selectedVehicle)
            )
          }
        )
      )
    )