How can I programmatically update 'Tax Group Code'?
headley27
Member Posts: 188
I have a need to automatically set the 'Tax Group Code' of a Sales Line to a value of 'Taxable' for records where 'Type = G/L Account' and 'No. = xxxxx'.
My thought was that I could use the 'Form - OnAfterGetCurrRecord()' trigger on the Sales Quote and Order Subforms to ensure that this is done. For Example:
What I find even more strange is that it seems to work occasionally but I can't pinpoint why.
Can anyone provide any insight as to what I am doing wrong?
Thank you very much.
My thought was that I could use the 'Form - OnAfterGetCurrRecord()' trigger on the Sales Quote and Order Subforms to ensure that this is done. For Example:
IF (Type = 1) AND ("No." = 'xxxxx') THEN
IF "Tax Group Code" <> 'TAXABLE' THEN
VALIDATE("Tax Group Code", 'TAXABLE');
This makes the Subform appear to have the correct value; however, when printing a Sales Order I receive an error:
-
You must specify Tax Group Code in Sales Line Document Type='Order',Document No.='xxxxx',Line No.='xxxxx'.
What I find even more strange is that it seems to work occasionally but I can't pinpoint why.
Can anyone provide any insight as to what I am doing wrong?
Thank you very much.
0
Answers
-
This code works but what is the difference?
SalesLine.RESET; SalesLine.SETFILTER("Document No.", "No."); SalesLine.SETFILTER(Type, 'G/L Account'); SalesLine.SETFILTER("No.", 'xxxx'); SalesLine.SETFILTER("Tax Group Code", '<>%1', 'TAXABLE'); IF SalesLine.FIND('-') THEN BEGIN REPEAT SalesLine."Tax Group Code" := 'TAXABLE'; SalesLine.MODIFY; COMMIT; UNTIL SalesLine.NEXT = 0; END;I placed the code on the Print Button Menu Items on the Sales Order Form.
All I can guess is that the MODIFY statement helps out here.
(Realizing that I can't use the MODIFY statement in the previously mentioned 'Form - OnAfterGetCurrRecord()' trigger.)
Is this a correct assumption?
Thanks again.0 -
headley27 wrote:This code works but what is the difference?
SalesLine.RESET; SalesLine.SETFILTER("Document No.", "No."); SalesLine.SETFILTER(Type, 'G/L Account'); SalesLine.SETFILTER("No.", 'xxxx'); SalesLine.SETFILTER("Tax Group Code", '<>%1', 'TAXABLE'); IF SalesLine.FIND('-') THEN BEGIN REPEAT SalesLine."Tax Group Code" := 'TAXABLE'; SalesLine.MODIFY; COMMIT; UNTIL SalesLine.NEXT = 0; END;I placed the code on the Print Button Menu Items on the Sales Order
1) Never filter option field for text constant!SalesLine.SETFILTER(Type, SalesLine.Type::"G/L Account");
2) Never use COMMIT, if it is not necessary
3) Do not change field which is part of the filter directly. Use some auxiliary variable:REPEAT SalesLine2 := SalesLine; SalesLine2."Tax Group Code" := 'TAXABLE'; SalesLine2.MODIFY; UNTIL SalesLine.NEXT = 0;4) Best trigger where set this is OnValidate of the field "No." on the Sales Line table. There you can set the values of other fields, when someone enters the no. Follow the standard Nav logic for that. You do not need to go through all lines and change the value, if the value is filled correctly when the line is created/changed.0 -
You could also specify the Tax Group Code on the Posting tab of the G/L Account and then the No. OnValidate trigger will copy it on to the line. This should be standard functionality in the NA database.Zarryn0
-
headley27 wrote:...
My thought was that I could use the 'Form - OnAfterGetCurrRecord()' trigger on the Sales Quote and Order Subforms to ensure that this is done.
...
Never put business logic on forms, put code like this at the table level.David Singleton0 -
Thanks for the advice.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

