Can't write data into the Default Dimension table

Victor_Hugo
Member Posts: 12
Hello Everybody,
I need to change the 'Value Posting' field of the 'Default Dimension' table so that all records which have 'DEPARTMENT' as 'Dimension Code' get their 'Value Posting' set to empty. After I run the report nothing is changed in the table. Is there something else to be done? The code is below.
Ps: I put the code in the OnPreDataItem trigger.
"Default Dimension".SETFILTER("No.", '33..499999999');
"Default Dimension".SETFILTER("Dimension Code",'DEPARTMENT');
"Default Dimension".FIND('-');
WHILE("Default Dimension".NEXT <> 0) DO BEGIN
"Default Dimension"."Value Posting" := 0;
"Default Dimension".MODIFY;
Any hElp is appreciated. Thanks.
I need to change the 'Value Posting' field of the 'Default Dimension' table so that all records which have 'DEPARTMENT' as 'Dimension Code' get their 'Value Posting' set to empty. After I run the report nothing is changed in the table. Is there something else to be done? The code is below.
Ps: I put the code in the OnPreDataItem trigger.
"Default Dimension".SETFILTER("No.", '33..499999999');
"Default Dimension".SETFILTER("Dimension Code",'DEPARTMENT');
"Default Dimension".FIND('-');
WHILE("Default Dimension".NEXT <> 0) DO BEGIN
"Default Dimension"."Value Posting" := 0;
"Default Dimension".MODIFY;
Any hElp is appreciated. Thanks.
0
Comments
-
1) Never use While - Do loop, use the Repeat - until.
2) You are not filtering for table no.
3) Never refer Option as integer (or just in some special cases). Use the operator :: to use correct value
4) Do not loop the variable in the OnPreDataItem, you have the OnAfterGetRecord for that.
5) Why there is the filter for "No." = 33..49999999?
Try this:SETRANGE("Table No.",MyTableID); SETRANGE("Dimension Code",'DEPARTMENT'); MODIFYALL("Value Posting","Value Posting"::" ");
You can call this e.g. in the report pre section and than you can do CurrReport.BREAK;0 -
Victor Hugo wrote:Hello Everybody,
I need to change the 'Value Posting' field of the 'Default Dimension' table so that all records which have 'DEPARTMENT' as 'Dimension Code' get their 'Value Posting' set to empty. After I run the report nothing is changed in the table. Is there something else to be done? The code is below.
Ps: I put the code in the OnPreDataItem trigger.
"Default Dimension".SETFILTER("No.", '33..499999999');
"Default Dimension".SETFILTER("Dimension Code",'DEPARTMENT');
"Default Dimension".FIND('-');
WHILE("Default Dimension".NEXT <> 0) DO BEGIN
"Default Dimension"."Value Posting" := 0;
"Default Dimension".MODIFY;
Any hElp is appreciated. Thanks.
For a start....
WHILE ("Default dimension".NEXT <> 0) DO....
You are skipping the first record.
"Default dimension".FIND('-') <---- You get the first record.
WHILE ("Default dimension".NEXT <> 0) DO...... <
you get the second record here
"Default dimension".... <====== you process starting on the second record.0 -
kine wrote:1) Never use While - Do loop, use the Repeat - until.
2) You are not filtering for table no.
3) Never refer Option as integer (or just in some special cases). Use the operator :: to use correct value
4) Do not loop the variable in the OnPreDataItem, you have the OnAfterGetRecord for that.
5) Why there is the filter for "No." = 33..49999999?
Try this:
You can call this e.g. in the report pre section and than you can do CurrReport.BREAK;
1) While is useful if properly used. "Never use while" is not that good of an advice. While is used when the condition needs to be checked before running the code in the loop, repeat is used when the condition is checked after running the code in the loop. Just try to use both properly.
example:exitLoop := false; WHILE ((Amount > 0) and (not exitLoop)) DO BEGIN Amount := Amount - "Item ledger entry".amount; IF ("item ledger entry".NEXT = 0) THEN exitLoop := TRUE; END;
"3) Never refer Option as integer (or just in some special cases). Use the operator :: to use correct value"
Both ways are valid ways. Internally navision translates it to the integer, so it makes no real diffference.0 -
apertierra and Kine,
The filter for "No." refers to the accounts that should have their posting values changed. I will correct the code and revert the results on Monday.
Thank you!0 -
apertierra wrote:1) While is useful if properly used. "Never use while" is not that good of an advice. While is used when the condition needs to be checked before running the code in the loop, repeat is used when the condition is checked after running the code in the loop. Just try to use both properly."3) Never refer Option as integer (or just in some special cases). Use the operator :: to use correct value"
Both ways are valid ways. Internally navision translates it to the integer, so it makes no real diffference.
Internally yes, it is integer, but the integer is not so readable as the Option value and can lead to problems when mixed e.g. when you need to change option order and you use the text export method to make the values correct in your code when changing the order...
Of course, my meaning is just a tip how to do your work, it is not a rule. But it is based on my experiences and I want to share them with you... 8)0 -
Hello Kine,
I used the code you pasted in here and it worked fine! Is it required to use a filter for table No. because that is the first field of the primary key? I also put a filter for the table No. in the code I wrote and it worked (even though that was not the most beautiful code someone has already written :roll: ).
Many Thanks,
Victor0 -
You are welcome... 8)
You need to filter the Table No. because else you can change default dimensions for other tables than you want. But of course this was not the source of problem (because without that you just changed default dim settings for all tables...).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