Data change register

lodgerlodger Member Posts: 16
edited 2004-07-09 in Navision Financials
Can anyone help.

We use a data change register in 2.4, similiar to that used in 3.7, to track changes to tables. We track an option field on the sales header which works when changed manually from the sales order form. However we also update this option box while running a report but this change is not registered in the DCR. Are there any suggestions how I can make this work, I am calling the dcr from the OnModify trigger within the sales header table.

lodger

Comments

  • GoMaDGoMaD Member Posts: 313
    I started working with Navision in 1998 but i haven't heard from the 2.4 version.

    But maybe the report only does an asignment (like fieldname := value) and not a validateion (like record.validate(fieldname,value)). The asignment only enters a value in the field and doesn't trigger the OnValidate trigger (where the logging code should be).

    Hope this helps!

    Regards,
    Now, let's see what we can see.
    ...
    Everybody on-line.
    ...
    Looking good!
  • nelsonnelson Member Posts: 107
    Actually, you should not be looking for a Field assignment - Rec.Field := Value - in order to replace it with a VALIDATE statement - Rec.VALIDATE(Field,Value).
    You should look for a MODIFY on the Report. That Rec.MODIFY command should then be replaced with Rec.MODIFY(TRUE) which will cause the OnModify trigger of the table to be run and, subsequently, your DCR code to be run.

    [edit]
    When doing this, take a careful look at the OnModify trigger.
    It can happen that the Report is intentionally not running this trigger because there is code in the trigger that shouldn't be executed.
    Nelson Alberto
  • lodgerlodger Member Posts: 16
    Appologies it's version 2.6. I have tried both suggestions and neither work.

    The code in the OnPreSection trigger of the report is:


    "Sales Header"."Order Status" := "Sales Header"."Order Status"::xxx;
    "Sales Header".MODIFY;

    The code in the OnModify trigger of sales header table only calls the dcr (dcr.CheckOrder (xRec,Rec);).

    Any more suggestions.

    lodger
  • nelsonnelson Member Posts: 107
    That's exactly what I said!
    You have to replace:
    "Sales Header".MODIFY;
    with:
    "Sales Header".MODIFY(TRUE);
    Nelson Alberto
  • lodgerlodger Member Posts: 16
    Hi nelson

    I tried it and it doesn't work. Thought I might be missing something so I posted the code. Any reason why it's not working?

    lodger
  • kinekine Member Posts: 12,562
    If you are using some self-made module, I can't help you, because I don't know how it works. Look inside your module if there isn't any conditions which will skip register process in some situations... :cry:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • RobertMoRobertMo Member Posts: 484
    First do what neslon suggests, then put this in OnModify but before a call of your function:
    MESSAGE('%1\%2',xRec."Order Status", rec."Order Status");
    This way you will see what value is in xRec.

    I remember that xRec sometimes just wasn't what it should be (old rec). I used following code as first line in OnModify:
    xRec.GET(Rec."PK Filed 1",Rec."PK Field 2");
    "PK Filed 1" is first field in primary key, "PK Filed 2" is second field in primary key, etc. For "Sales Header" it sholud look like:
    Rec.GET(Rec."Document Type",Rec."No.");
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • fbfb Member Posts: 246
    Two items...:

    1) My experience has been that whenever the 'current record' is not the base record of a form (i.e. is not 'Rec' in some form), then xRec does not seem to be 'a copy of the record as originally read from the db', but rather seems to be just a copy of the record. Therefore, any mods to the record are 'instantly' reflected in xRec, and table trigger code that depends on the differences between Rec and xRec will not work.

    2) Navision code uses the following pattern to log changes to a record, whenever a 'loggable' change is made outside the context of a form (see for example codeunit 103 - Cust. Entry-Edit):
    //pseudocode...
    save currRec in oldRec;
    modify currRec;
    call LogModification with currRec, oldRec;
    
    So, in your report trigger, you might write:
    oldHdr := "Sales Header";
    "Sales Header"."Order Status" := "Sales Header"."Order Status"::xxx; 
    "Sales Header".MODIFY; 
    dcr.CheckOrder(oldHdr,"Sales Header");
    
  • RobertMoRobertMo Member Posts: 484
    fb, this also looks as good idea ! The code in OnModify is still needed to log changes that are made manually through forms and the programmer must be careful in code when to use MODIFY(TRUE) and when MODIFY(FALSE).
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • lodgerlodger Member Posts: 16
    Thanks fb and RobertMo

    I used fb's suggestion as it keeps the code in the report and it works GREAT!

    I created 2 global variables
    oldHdr, Record, Sales Header and
    dcr, Record, Data Change Register

    Is this correct? It must be as it works and doesn't appear to affect anything else.

    Thanks again for the help.

    lodger
Sign In or Register to comment.