How to get Data from RecordData ?

Certified Senior Developer

Hi,

I have a recordData used to display a simple grid.
How may I take advantage of the local!data var ?  I woud need to get the TotalCount of this RecordData for example, or to copy data in a CDT list.
Have I to cast this variable ?

  local!data: a!recordData(
    recordType: 'recordType!TT_R_Vehicles',
    filters: a!queryLogicalExpression(
      operator: "AND",
      filters: {
        a!queryFilter(
          field: 'recordType!TT_R_Vehicles.fields.model',
          operator: "=",
          value: "BMW"
        )
      },
      ignoreFiltersWithEmptyValues: true
    )
  ), 
  
  a!gridField(
    label: local!labels.units,
    labelPosition: "ABOVE",
    data: local!data,
    columns: {

  Discussion posts and replies are publicly visible

  • I believe we would need a little more information on what you are trying to accomplish and what issues you are running into.  Have you reviewed the SAIL Recipe here which utilizes a!recordData() to display a grid?

  • 0
    Appian Employee
    in reply to Chris

    a!recordData() is only for defining data from a record type within certain components, to query data you want to you a!queryRecortType()

  • 0
    Certified Senior Developer
    in reply to Chris

    Thank you for the link. Yes, my grid works perfectly.

    I just need to know how may I get TotalCount information from a RecordType or RecordData, or how to convert RecordType/RecordData to a dictionary or CDT list. 

    Let's imagine this little scenario :

    I have a Grid connected to a recordType/recordData, and then when I click to a Button placed near the grid, I need to display the TotalCount of lines (filtered data) that contains this grid.

    My second need is to be abble to make a foreach on that data (like I would do with query dictionary result).

  • 0
    Certified Senior Developer
    in reply to Danny Verb

    Thank you Danny, you mean :

    make a first call to a!recordData (with some user filters) to define the filtered data to display in my grid, and then make a 2nd call to a!queryRecortType() with the same user filters to get my data ?

    Is it not possible to do these 2 actions with the same data object ? 

    (I mean juste use a!queryRecordType to get the data but also to connect it to the grid)

  • 0
    Appian Employee
    in reply to cedric01

    You don't need to use a!recordData and a!queryRecordType, you can just use one. For example: 

    local!pagingInfo: a!pagingInfo(1,20),
    local!data: a!queryRecordType(
        recordType: 'recordType!TT_R_Vehicles',
        filters: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: 'recordType!TT_R_Vehicles.fields.model',
              operator: "=",
              value: "BMW"
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: local!pagingInfo,
        fetchTotalCount: true
      ), 
      {
        a!textField(
            label: "Count",
            readOnly: true,
            value: local!data.totalCount
        ),
        a!gridField(
            label: local!labels.units,
            labelPosition: "ABOVE",
            data: local!data,
            columns: {},
            pagingSaveInto: local!pagingInfo
        )
      }

  • 0
    Certified Senior Developer
    in reply to Danny Verb

    Thank you Danny, but your code works only, if you use a standard gridField (with standard columns).

    In my concern, I'm using RecordType column components in my grid and RecordType attributes (user filters, searchBox...), so in that case, using your code throws this error:

    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!gridField [line 64]: A grid component [label=“vehicles”] has an invalid value for “userFilters”. “userFilters” and “showSearchBox” may only be specified when “data” is sourced from a Record Type.

    Here is an example of grid RecordType definition using your local!data:

    a!gridField(
        label: local!labels.vehicles,
        labelPosition: "ABOVE",
        data: local!data,
        columns: {
          {
            a!gridColumn(
              label: "#",
              sortField: 'recordType!TT_R_Vehicles.fields.id',
              value: fv!row['recordType!TT_R_Vehicles.fields.id'],
              align: "END"
            ),
            a!gridColumn(
              label: local!labels.commodityLabel,
              sortField: 'recordType!TT_R_Vehicles.fields.model',
              value: fv!row['recordType!TT_R_Vehicles.fields.model'],
              align: "CENTER",
            ),
          }      
        },
        initialSorts: {
          a!sortInfo(
            field: 'recordType!TT_R_Vehicles.fields.id'
          )
        },
        selectable: true,
        selectionStyle: "ROW_HIGHLIGHT",
        selectionSaveInto: {},
        validations: {},
        refreshAfter: "RECORD_ACTION",
        userFilters: if(ri!showFilters, {
          'recordType!TT_R_Vehicles.fields.model',
          'recordType!TT_R_Vehicles.fields.make',
          'recordType!TT_R_Vehicles.fields.year',
          },
          null),
        showSearchBox: true,
        showRefreshButton: false,
        showExportButton: true,
        recordActions: {}
      )

  • Using the a!queryRecordType, you don't need to use recordType! to reference the data for each column.  You should be able to reference each element directly, for example try fv!row.data,id and fv!row.data.model.

  • 0
    Certified Senior Developer
    in reply to bryant.st39

    Danny, , what you have advised me seems a good way (I've already tried it a lot of times), but it does not work:

    When a RecordType-based-grid is referencing a a!queryRecordType, the Grid can not use anymore the RecordType functionalities (user filters, searchBox)...
    Of course, I need to keep these functionalities.

    So, if you have any other idea, it would be great ;-)

    Error:
    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!gridField [line 51]: A grid component [label=“Vehicles”] has an invalid value for “userFilters”. “userFilters” and “showSearchBox” may only be specified when “data” is sourced from a Record Type.

    a!localVariables(
    
      local!pagingInfo: a!pagingInfo(1, 20),
      local!data: a!queryRecordType(
        recordType: 'recordType!CJT_R_Vehicles',
        filters: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: 'recordType!CJT_R_Vehicles.fields.isavailable',
              operator: "=",
              value: true
            )
          },
          ignoreFiltersWithEmptyValues: true
        ),
        pagingInfo: local!pagingInfo,
        fetchTotalCount: true
      ),
    
      a!formLayout(
        label: "Grid with RecordType",
        contents: {
          
          a!textField(
            label: "Count",
            readOnly: true,
            value: local!data.totalCount
          ),
    
          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: "Value",
                sortField: 'recordType!CJT_R_Vehicles.fields.value',
                value: if(
                  isnull(fv!row['recordType!CJT_R_Vehicles.fields.value']),
                  fv!row['recordType!CJT_R_Vehicles.fields.value'],
                  fixed(fv!row['recordType!CJT_R_Vehicles.fields.value'], 2)
                ),
                align: "END"
              )
            },
            
            initialSorts: {
              a!sortInfo(
                field: 'recordType!CJT_R_Vehicles.fields.id'
              )
            },
            showWhen: true,
            selectable: false,
            selectionStyle: "ROW_HIGHLIGHT",
            selectionValue: null,
            selectionSaveInto: {},
            validations: {},
            refreshAfter: "RECORD_ACTION",
            userFilters: {
              'recordType!CJT_R_Vehicles.filters.value'
            },
            showSearchBox: true,
            showRefreshButton: false,
            showExportButton: false,
            recordActions: {}
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "save",
              saveInto: {},
              submit: true,
              style: "PRIMARY",
              showWhen: true
            ),
            
          },
         
        )
      )
    )

  • 0
    Certified Senior Developer
    in reply to maheshg4310

    If you want to use the a!queryRecordType() to query record data and also want to utilize record features like user filters, search record or Export excel then there is absolutely no way around and you only have to query the record type twice for fetching the totalCount using a!queryRecordType() and for gridField() data using a!recordData(). The only possible way but not at all feasible in this case is to manually create OOTB record features functionality using SAIL design components and smart services but instead of putting all this huge amount of extra effort simply querying the recordType twice is more suitable.