Filter subform

Solution (Verified) This post has 1 verified solution | 7,806 Views | 13 Replies | 1 Follower

82 Posts
675 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal
Luís Correia posted on 2011-9-21 12:21 rated by 0 users

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?

Solution (Verified) Verified Solution

108 Posts
2,810 Points
Joined: 2010-4-22
Last Online:
2014-8-28 17:35
Location: Germany

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:

CurrForm.MySubForm.FORM.SETTABLEVIEW(recDiarioFusao);

Or via function on the Subform as suggested.

 

  • | Post Points: 106

All Replies

5,129 Posts
117,398 Points
Joined: 2009-2-17
Last Online:
2016-2-12 14:03
Location: Hyderabad, India
DynamicsMVP
ModeratorDynamicsNAV

Check SubFormLink propery in subform..

  • | Post Points: 6
82 Posts
675 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal

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...

  • | Post Points: 6
5,129 Posts
117,398 Points
Joined: 2009-2-17
Last Online:
2016-2-12 14:03
Location: Hyderabad, India
DynamicsMVP
ModeratorDynamicsNAV

You need to try by adding filter code to subform records in Onvalidate trigger of main form field..

  • | Post Points: 6
82 Posts
675 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal

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);

  • | Post Points: 6
5,129 Posts
117,398 Points
Joined: 2009-2-17
Last Online:
2016-2-12 14:03
Location: Hyderabad, India
DynamicsMVP
ModeratorDynamicsNAV

I think you need to create a function in Subform and call it from main form by passing the field value

CurrForm.SalesLines.FORM.Filterlinerecords(mainrec.field);

  • | Post Points: 7
Male
1,432 Posts
32,546 Points
Joined: 2007-3-2
Last Online:
2014-5-13 19:42
Location: Houston, TX, USA
DynamicsMVP

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?

  • | Post Points: 6
82 Posts
675 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal

I read that somewhere, and it makes sense, but what would that function do?

  • | Post Points: 5
108 Posts
2,810 Points
Joined: 2010-4-22
Last Online:
2014-8-28 17:35
Location: Germany

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:

CurrForm.MySubForm.FORM.SETTABLEVIEW(recDiarioFusao);

Or via function on the Subform as suggested.

 

  • | Post Points: 106
5,129 Posts
117,398 Points
Joined: 2009-2-17
Last Online:
2016-2-12 14:03
Location: Hyderabad, India
DynamicsMVP
ModeratorDynamicsNAV

Function should filter the Line records based on the passed value..

  • | Post Points: 6
82 Posts
675 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal

Thomas Martin's solution worked. Thanks!!

  • | Post Points: 6
5,129 Posts
117,398 Points
Joined: 2009-2-17
Last Online:
2016-2-12 14:03
Location: Hyderabad, India
DynamicsMVP
ModeratorDynamicsNAV

if you modify the value in main form type field from abc to xyz?

is it filtering the subform?

  • | Post Points: 6
82 Posts
675 Points
Joined: 2011-7-6
Last Online:
2013-5-6 19:11
Location: Guimarães, Portugal

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).

  • | Post Points: 6
5,129 Posts
117,398 Points
Joined: 2009-2-17
Last Online:
2016-2-12 14:03
Location: Hyderabad, India
DynamicsMVP
ModeratorDynamicsNAV

Luís Correia:
because it's not an editable field.

Yes

  • | Post Points: 5
Page 1 of 1 (14 items) | Get this RSS feed