fields that depend on fields of the same record...

mxcmxc Member Posts: 42
edited 2003-08-29 in Navision Attain
I've created a field in the table "Cust. Ledger Entry" (Yes, I know I shouldn't...). Its value depends on the value of several fields of the same record and of other records from the table. How can I make its calculation automatic, every time a record is inserted?
Note: Since this table is updated by several forms, I would rather insert C/AL on the table itself...
Regards,

Manuel Xavier

Comments

  • WaldoWaldo Member Posts: 3,412
    I think you should do the following:

    Just make a seperate procedure (in which you make the calculation) in your Cust. Ledger Entry table, and call this procedure in the OnModify and OnInsert (mostly at the end) trigger.

    If this doesn't do the job (When the code does INSERT(FALSE) on the Cust. Ledger Entry table, the OnInsert trigger isn't triggered and your procedure will not be called), you might think of calling the procedure on the OnValidate-trigger of every relevant field.

    You also mention the value depends on other records in the same table ... well, in your seperate procedure, you can make a record-variable of the table you're working in.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • mxcmxc Member Posts: 42
    I tried to make a simple debug to check wich triggers were called when the insertion was done (using MESSAGE('Trigger xpto');) and I got no messages when I did a simple thing like posting an invoice...
    What can it be?
    Regards,

    Manuel Xavier
  • WaldoWaldo Member Posts: 3,412
    Then I guess you have to find out where Navision inserts the record in the Customer Ledger Entry (I couldn't find it in codeunit 80), and specify your code there ... .

    you could use code coverage for this ...

    sorry I can't be a bigger help ...

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • WaldoWaldo Member Posts: 3,412
    Wait, I found it (stupid me ...).

    You'll have to look in codeunit 12, probably specifically to the PostCust-procedure.

    Please let me know if you succeeded.

    Good luck!

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • mxcmxc Member Posts: 42
    Ok, thanks. I'll try it and then I'll let you know...

    One more question, what's code coverage?
    It is my 1st time working with navision...
    Regards,

    Manuel Xavier
  • WaldoWaldo Member Posts: 3,412
    When you click Tools/Debugger/Code Coverage, you get a form with a start/stop functionality.

    When you start, the form starts to list all code executed, until you press stop. Afterwards you can go through the executed code.

    Just play with it, and it will be clear right away ... .

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • mxcmxc Member Posts: 42
    Thanks for all your tips.
    I was able to run my code using the codeunit 12...
    Regards,

    Manuel Xavier
  • nunomaianunomaia Member Posts: 1,153
    Normally I use SumIndex Fields (when is Possible) for fields that need dynamic calculation
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • eromeineromein Member Posts: 589
    Hi,

    If you don't have to filter on the field, this means it's only a field the user want to see on the form, you could just add a new label and tablebox to you form and type a formule in the source expression of this field.
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
Sign In or Register to comment.