I'm new to AL Language and would like to build a Freight Calculator as project to get started.
I was able to create a Table, a list page and a card page using VS Code. With this created, I also managed to use the Configuration Packages Page to import data into my newly created Table... this was somewhat self explanatory.
Where I'm having a hard time is finding information about the followings:
My Table has 11 columns, Origin City, Service Type, Destination City, Destination Province, Base Rate, then 6 other columns of rates based on weight.
I need to create a UI where the user can select their Origin City, Service Type, Destination City and Province and input the weight that they would like to ship. The result would be the price for the freight.
I understand that this might not be as easy as doing it in c# Winform, but there must be a way.
I'm not looking for someone to write it for me but more info on where to get started.
Thanks in advance.
No, there is no way to update option list of an Option type variable dynamically. Correct solution for this problem is to extract each separate entity into its own table. It means create tables for cities and provinces and setup table relations.
I followed your suggestion and created a new Table for my Destinations. I've setup the table with 2 fields. Province and Cities.
Unfortunately, the Province drop down only displays the cities. I would like to have it behave like the Postal Code (Zip Code) table. Where if you start typing in the city, it shows you both city and province then when you have a smaller number of record visible, you select 1 and it populates both the city and province field.
Am I asking for too much at this time in AL?
Was all of this possible in C/AL but they haven't implemented it in AL?
Should I start developing in C/AL and switch to AL when it gets better?
I have to say, this language is very non-intuitive. Nothing like a C based language.
Thanks again Alexander for your time and your responses... Hopefully I can pay it back later.
AL has some limitations compared to C/AL, but drop-down functionality is not one of them. You can do the same things in both.
To show certain fields in the drop-down list, create the Dropdown field group in your table: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-field-groups
As for the Zip code selection that populated several fields, here you need to do some coding to make it behave like this. Controls with lookups to the Post Code table call the function PostCode.ValidateCity in their OnValidate triggers. You will need something like this too - in the trigger OnValidate, assign all the field you need populated.
I got my 2 drop downs working great. They both get their data from the same table which stores Provinces and Cities.
On the windows Client, when I type in the Province Field, the displayed table gets filtered down. When in the City Field, typing the city name filters things down.
Where i'm a little lost is how to get the "record" that was selected. I would like to get the selected record and store it into a record variable so that I can update the City field when working from the Province field or update the province field when working from the city field.
I am able to set the fields statically but I need the selected record to do it dynamically.
This thread is turning into a "Complete guide to Business Central UI development" :-)
You can't access the related table when the reference is configured as a "TableRelation" property. It's all controlled by the platform, and it returns only one field value. You have full control over the related record if you implement it in the AL code, OnLookup trigger. But then the selection list can only be displayed as a lookup page, not a drop-dowm list. Oops, we have already been there...
So, I see four options here to choose from:
1) Make the user select the city in two steps: "Provinces" control shows only the list of provinces, "City" filters the list of cities by the selected province. That's the traditional NAV way of work, and that's what I recommend to do.
2) Do a trick and introduce a surrogate primary key to your province/city table - a simple integer number. TableRelation reference will yeild this number, and you can use it in the OnValidate trigger to retrieve the record. Drawback: when the user selects a record, they will see a strange number instead of the province code until they move the focus to another field.
3) Forget the drop-down and opt for a lookup page - do everything you need in the OnLookup trigger.
4) Custom controls in JavsScript.
Probably not a bad thing to have more information online about AL Programming...I want to thank you very much for all your insight and help... I picked up Programming Microsoft Dynamics 365 Business Central, Sixth Edition by Mark Brummel last night and I'm only in chapter 2 and it starting to get much clearer. It has exactly what I was looking for... I will follow up shortly with my solution.Thanks again.Yann