Problem when applying a filter in a grid field displaying related data

Certified Associate Developer

Hello,

I hope you can help me.

I have a gried Field with a record Type as the data source (record A), which at the same time is based on a SQL table. Every row has a unique value of its primary key (request_id).

Some of the columns of the grid are displaying values which are not from the main source record, but from another record with a one-to-many relationship.
This second record (record B) is also based on a SQL table.  The relationship between them is through request_id. Because of this, I have included record B within the "relatedRecordData" parameter of the "a!gridField". I have stablished as well a limit of 1, and a descending sort field based on the date. This way, for every a_id, I only display the value of the latest row in record B (even if there are more rows with different values).This is working completely find.

My problem comes when I try to add filters within "a!recordData" > "filters" .

The moment I add a filter that affects a field which is from record B, it also shows matches with values from rows that are not the last ones (the ones I am displaying).

For example; I have a column called "status" with different values such as "Started", "Completed" or"Canceled". If I select "Completed" in my multiple dropdown field, it displays rows which visible status is different to "Started", because in the record B, some of the rows for the same request_id have that particular status. This is wrong as I just want the filter to apply to the latest row of record B. 


If the data from the record B table looks like this:

request_id status created_date
1 completed today
1 started 1 day ago
2 canceled today
2 completed 1 days ago
2 started 2 days ago
3 started today

For each request_id, the grid displays just 1 (the one with the most recent date):

request_id status created_date
1 completed today
2 canceled today
3 started today

but, if i apply the filter status= completed, it displays :

request_id status created_date
1 completed today
2 canceled today

This is because reques_id also has status = "completed" in ones of its rows of the the record B table, but this is not what I want. It should only filter those that have status = "completed" in the very last row;

request_id status created_date
1 completed today

I have to add that I have also try to add the filters in the "relatedRecordData" section, but it also did not fix the problem.

What am I missing? It cannot be that an out of the box function as the grid Field with records as a source, and the filters of it are not working as intended...

Thanks for any help. 

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Senior Developer
    in reply to Fernando Briones

    In the recordData, use if() condition for your relatedRecordData filters and the limit. 

    a!recordData(
      relatedRecordData: a!relatedRecordData(
        relationship: "your record relationship",
        filters: if(
          a!isNullOrEmpty(ri!dropdownValue),
          {"apply query filter"},
          {}
        ),
        limit: if(
          a!isNullOrEmpty(ri!dropdownValue),
          {"apply limit"},
          {}
        )
      )
    )

  • 0
    Certified Associate Developer
    in reply to Konduru Chaitanya

    Thanks again for the answer.

    I think that in my case the limit should always be thereand fix to one. I always want just one row of the related record to be shown...

    And regarding the filter, I have tried what you mention, and it is also not fixing the problem...
    When I activate the filter = completed, it still shows me 2 rows when it should only show 1. The main difference is that now, the second row has changed its status to "completed", but it is because it displaying the info of a different row of record B, and not the one that I want...

    Also, isn't the "if" statement the same as just putting the condition of "applyWhen" within the a!queryFilter ? 

    Thanks again

  • 0
    Certified Senior Developer
    in reply to Fernando Briones

    Sorry, yes. I have totally forgot. Yes you can simply use the applyWhen parameter for the filter. If for the limit. But then since you need only one item and the limit is constant you can go just try using the applywhen for the filter.

    I think you need to show your data and also the screenshots of whats happening.

  • 0
    Certified Associate Developer
    in reply to Konduru Chaitanya

    thanks again:
    So, initial grid:

    If i select the status = "draft"; 

     

    As you can see, this is not good because the status of the seond row is "approved" and not "draft". This is due to the fact that for the request_id "24-00238", there are multiple rows in record B, and 1 of them (which is not shown because I am only displaying the last row), has the status "draft". 

    If i change the code, and I add a filter as you mentioned, this happens:

    now the filter is active, and the only data in the grid is with status "draft", but you can see that the information is not correct, as now the second row is displaying information which is from record B, but not the row with the latest information... you can see a red circle sorounding those values that have changed...

    Am i explaining now?

    Thanks again

  • 0
    Certified Associate Developer
    in reply to Konduru Chaitanya

    Sorry for the late response,  ,I tried attaching screenshots and it did not allow me initially and I think an AI had to verify the comment...