TableRelation in C/AL Code ?

Hello everybody :slight_smile:

I have a little question, can I realize a TableRelation in my C/AL Code ?

Because i want to make TableRelation with condition IF. I have tried SETFILTER and SETRANGE without success.

Thanks in advance


Can you provide a bit more detail of what you are trying to accomplish? Possibly and example.

I have a Dynamics NAV Module for material allocation request.

In this module i can select material from resource Table.

Resource table with an additionnal column which is ‘Available’ a boolean.

I want to display in my request module only the available products.

So what you need is to set a filter in a page to only display Resources with Yes in Available? Or?

If yes, then Resource.SETRANGE(Available,TRUE) would do it.

Yes but it doesn’t works :confused:

I have put resource.SETRANGE(Available,TRUE) in the OnOpenPage trigger of my Allocation Request card page.

Ok, then let’s take a step back.

Please let’s know which version you’re working on, which page type. And is the source table of the page the resource table?

I’m on the version 2013, it’s a Card TypePage. The source is a custom table.

I’m working on the 2013 version. My page type is Card and the source table is a custom table.


Please set a filter in Table filter or plese type the following in table filter field Available=FILTER(Yes)



Thank you. And is the “Available” field a field on this custom table?

No, Available is a field that I have add to the Resource table. That’s why I have create a C/AL Globals (Record)

Ok then I understand your frustration!

And what is your plan in regards to the Resource table? Do you have a field where you want to enter the Resource No. from the Resource list, but only display Resources where Available = Yes?

If yes, then normally you would create a code type field in your custom table. Here you need to set the table relation on that field to something similar to:

“Resource WHERE (Available=CONST(TRUE))”

Yes thanks Erik, but I want to do that in C/AL because i don’t want to apply this any time.

I suppose i must use FILTER ? But it doesn’t works.

So the please tell me exactly what it is that you’re trying to do. Step by step in details.

Hi There,

You can use a record variable , filter records you wish (Same as filters you need in table relation) and then pass the record variable to the page and run the page in C/AL Code.

In the Page where you want to input use a unbound field and upon successful validation pass the value to actual field (bounded field)

You can find similar examples in NAV in Sales , Purchase , INV reservation and Manufacturing modules.

Hello Erik,

the step are :

  • I have a Card page

  • In this Card page, i can create a request for material allocation

  • In this request, user must choose a resource (material).

  • This resource can be available or not

  • That i want is to only display available material in field “Mat. No.” (Material are from Resource table)

Thanks in advance :slight_smile:


And one last question. Is the “Mat. No.” control an actual field in your table or is it just a variable defined on the page?

Mat No. is a field in my custom table (which save the request)

Ok good.

Then go back to my reply where I suggested you to insert this filter on your custom field:

“Resource WHERE (Available=CONST(TRUE))”

That should solve your problem. If you want to set the table relation manually, then you specify this filter in the Table Filter:


The only potential problem I can see is if the field Available is not a normal field but a calculated flow field. Then it’s a bit more advanced to do this.

Yes, Erik but as i said i want to make this restriction by C/AL because i don’t want to apply this restriction all the time.

I want make this restriction cover by an IF condition. I have already tried this TableRelation and it works but it’s not really answer to my expectation.