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:
For each request_id, the grid displays just 1 (the one with the most recent date):
but, if i apply the filter status= completed, it displays :
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;
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
Hello Fernando Briones
Not sure if I clearly got your requirement, but from what I understood you can simply use a if() condition to evaluate whether the relatedRecordData or the limit applies based on a null check for the status selected. But this will not work if the filters are User filters. This would be doable only if you have a custom filter created using dropdown outside the grid.
Hello Konduru Chaitanya ,
Thanks for your answer! Yes, the filters are not user filters, but filters within a!griedFiled > data > a!recordDara > filters and the values are influenced by multiple dropdows I have outside the grid. To be honest, I do not really understand what exactly is that I should evaluate or where exactly... Could you be a bit more specific? I can also try to rephrase something in case I was not clear enough with the problem...Thanks again
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"}, {} ) ) )
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
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.
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
Sorry for the late response, Konduru Chaitanya ,I tried attaching screenshots and it did not allow me initially and I think an AI had to verify the comment...