Default field in subform!

nverma
Member Posts: 396
I wanted to setup a default value to a field, everytime a fixed asset card was created.
After doing a bit of searching on the form, i found out that doing it the INITVALUE is not really a good way of doing it. So I tried doing it the way you guyz suggested it. I went to FASetup table and card and created a new field called Default Depr Book code and I also set the table realation in the fa setup table to the depreciation book table.
In the field I want it to display 'OMOD' as soon as a fixed asset card is created.
At first i tried to do it in the FA Card Header onInsert (trigger) but that didnt work, because the FA card has to be created first, then only I can do some calculations on it. So then I tried setting it up onInsertRecord (trigger) in the subfrom, but that didnt work aswell. What am i doing wrong??
Code in the subfrom tigger:
Any idea what I might be messing up on???
After doing a bit of searching on the form, i found out that doing it the INITVALUE is not really a good way of doing it. So I tried doing it the way you guyz suggested it. I went to FASetup table and card and created a new field called Default Depr Book code and I also set the table realation in the fa setup table to the depreciation book table.
In the field I want it to display 'OMOD' as soon as a fixed asset card is created.
At first i tried to do it in the FA Card Header onInsert (trigger) but that didnt work, because the FA card has to be created first, then only I can do some calculations on it. So then I tried setting it up onInsertRecord (trigger) in the subfrom, but that didnt work aswell. What am i doing wrong??
Code in the subfrom tigger:
FASetup.TESTFIELD("Default Dep. Book Code"); FADeprBook.INIT; FADeprBook.VALIDATE("Depreciation Book Code", FASetup."Default Depr. Book"); FADeprBook.VALIDATE("FA No.", Rec."No."); FADeprBook.INSERT;
Any idea what I might be messing up on???
0
Comments
-
Don't ever write data code on forms. Stuff like this belongs in table code.
You have to think your way through the problem. Take it one step at a time.
Step 1: a default value needs to be populated when a fixed asset card is created. The point at which any record is created is in OnInsert of the table. You want it on the fixed asset card, so that would be the "Fixed Asset" table.
Step 2: The value comes from the fixed asset setup table, for which you've created a default field -> good
Step 3: Now you need to create a "FA Depreciation Book" record.
Step 3a: Figure out how this works. Turn on the debugger, and create one by hand. Write down what happens.
Step 3b: Figure out how that relates to the Fixed Asset record, make sure you understand the link.
Step 4: Now you know WHERE to write the code, and you've written down HOW it happens. From there it's just a matter of writing the proper C/AL code.
Step 5: TEST
It looks like you're on the right path, but forget about EVER writing data code like that on forms.0 -
Fixed Asset Table and FA Deprecation Book are linked by FA No.0
-
Yes I know how it works, I'm trying to help you figure it out yourself. I'm not going to give you the code if that's what you are after.0
-
DenSter wrote:Don't ever write data code on forms. Stuff like this belongs in table code.
You have to think your way through the problem. Take it one step at a time.
Step 1: a default value needs to be populated when a fixed asset card is created. The point at which any record is created is in OnInsert of the table. You want it on the fixed asset card, so that would be the "Fixed Asset" table.
Step 2: The value comes from the fixed asset setup table, for which you've created a default field -> good
Step 3: Now you need to create a "FA Depreciation Book" record.
Step 3a: Figure out how this works. Turn on the debugger, and create one by hand. Write down what happens.
Step 3b: Figure out how that relates to the Fixed Asset record, make sure you understand the link.
Step 4: Now you know WHERE to write the code, and you've written down HOW it happens. From there it's just a matter of writing the proper C/AL code.
Step 5: TEST
It looks like you're on the right path, but forget about EVER writing data code like that on forms.
:thumbsup: :thumbsup:0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions