Hi there.This may seem like a silly and beginner question, but I haven't found the answer anywhere.I have a form, with a subform in it, and I need to filter a field on the subform (list), based on the value of another field in the main form (card).For example, my current record in the main form has a field called "type", and its value is 'abc', I want to filter the subform's "type" field with the value 'abc'. Only the lines whose "type" value is 'abc' should appear on the subform.How do I do it?
Check SubFormLink propery in subform..
In reply to Mohana:
I did. But I haven't been able to filter the subform.
In any case, i'd prefer to filter the subform via code, since I need to set another condition, in which the filter depends on the value of another field in the form...
In reply to Luís Correia:
You need to try by adding filter code to subform records in Onvalidate trigger of main form field..
Still haven't been able to filter
I wrote this code on the OnAfterGetRecord trigger of the main form. Is there something missing?
(the form_diario_fusao is a form variable of the subform,)
recDiarioFusao.RESET; recDiarioFusao.CALCFIELDS(DescMaterial); recDiarioFusao.SETRANGE(DescMaterial, "Cod. Material"); IF recDiarioFusao.FINDFIRST THEN MESSAGE('%1', "Cod. Material"); recDiarioFusao.CALCFIELDS(DescMaterial); MESSAGE('%1', recDiarioFusao.DescMaterial); form_diario_fusao.SETTABLEVIEW(recDiarioFusao);
I think you need to create a function in Subform and call it from main form by passing the field value
Also, just think about where you put your code. OnAFTERGetRecord. As in you have already gotten the data. Would you filter the data after you've already gotten it from the database, or before?
Matt Traxinger - ArcherPointMicrosoft Dynamics NAV 2009 Programming Cookbook
Do you have an idea to improve NAV? Submit it on I Love NAV
In reply to Matt Traxinger:
I read that somewhere, and it makes sense, but what would that function do?
You need to reference directly to the Subform control and not just another instance of the form.
Give the subform control a name in the properties. Let's say MySubForm.
Then you can use:
Or via function on the Subform as suggested.
In reply to Thomas Martin:
Function should filter the Line records based on the passed value..
Thomas Martin's solution worked. Thanks!!
if you modify the value in main form type field from abc to xyz?
is it filtering the subform?
Yes and no.No, because it's not an editable field.Yes, because it changes when I change the record (and the value is different).
Luís Correiabecause it's not an editable field.