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.
0
Comments
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;
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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.
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: "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.
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!
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)
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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,
Victor
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...).
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.