Options

Can't write data into the Default Dimension table

Victor_HugoVictor_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.

Comments

  • Options
    kinekine Member Posts: 12,562
    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;
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    apertierraapertierra Member Posts: 61
    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.
  • Options
    apertierraapertierra Member Posts: 61
    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;
    Well...
    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.
  • Options
    Victor_HugoVictor_Hugo Member Posts: 12
    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!
  • Options
    kinekine Member Posts: 12,562
    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.
    I mean for iterating records. In While - do the record cache can be handled wrongly leading to bad performance.
    "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)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    Victor_HugoVictor_Hugo Member Posts: 12
    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,

    Victor
  • Options
    kinekine Member Posts: 12,562
    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...).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.