Options

How to get Table-ID in OnModify() trigger

navvynavvy Member Posts: 79
Hi,

I have to do some coding in an OnModify trigger of a table. Is there a function or a variable I can use to get the ID of the appropriate table ?

I also want to make a function in a codeunit which will use FieldRef to return all field names of a table. This function will be called by an external COM-application.
My second question is: Should I use Table Name or Table ID as parameter to call this function (which change not or maybe less) ? The problem is, if a table will be renumbered or renamed, my external application will no longer be able to get the field names (the function won't find the table).

Best Regards,
navvy
navvy
Freelance Developer

Comments

  • Options
    krikikriki Member, Moderator Posts: 9,096
    -There is no way to get the TABLE ID of the table. You have the TABLENAME-property of rec. With this you can search in table "Object", but it is not so fast. But I would just use DATABASE:"Your Table" to have the ID. The negative is that you need to manually change it in each table (in case you copy the table to another ID).

    -The best way is to use the table ID. There is less change someone changes the ID of an object. The name can be easily changed in NAV without any problems.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    navvynavvy Member Posts: 79
    Hi kriki

    Thanks for the help :) What do you mean with "But I would just use DATABASE:"Your Table" to have the ID. ", where should I use this ?

    Last question: Is it possible to track renumbering of tables e.g. is there a certain trigger which I can use ?

    navvy
    navvy
    Freelance Developer
  • Options
    kinekine Member Posts: 12,562
    Renumbering table is more complex process than only renumbering. You need to change all relation in all other objects. It means that it is not done as common function. It is big job to renumber objects in NAV correctly.

    Table ID: If you use RecordRef, you can use the recref.NUMBER to get the ID of the table. And how to create RecRef from Record you know... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    krikikriki Member, Moderator Posts: 9,096
    navvy wrote:
    Thanks for the help :) What do you mean with "But I would just use DATABASE:"Your Table" to have the ID. ", where should I use this ?

    Give this a try:
    int := DATABASE::"Sales Line"; // int is an integer variable
    MESSAGE('The integer value is <%1>',int);
    

    So DATABASE::"Sales Line" is like an integer constant and is more readable than 37.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    navvy wrote:
    Hi,
    I have to do some coding in an OnModify trigger of a table. Is there a function or a variable I can use to get the ID of the appropriate table ?
    How about :
    RecRef.GETTABLE(Rec);
    Message('%1', RecRef.NUMBER);
    
    where RecRef is a local variable of RecordRef type...

    Slawek.

    EDIT:
    Oops... Kine already suggested this :(
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Options
    VjekoVjeko Member Posts: 55
    A late reply to this thread, but here's another solution, which enables you to get any object ID from any object type:

    http://vjeko.com/blog/detecting-current ... et-interop
    (Co-)author of "Implementing Microsoft Dynamics NAV 2009"
    http://vjeko.com/
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Vjeko wrote:
    Vjeko, quoting your blog:

    "In C# you can easily get access to the current method, or the method that called the current method"

    Now - can you do THIS in NAV ? :D
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Options
    thegunzothegunzo Member Posts: 274
    Hi Slawek.

    Vjeko did this in NAV using dotnet interop. Just look at his blog and the downloadable objects.
    Excellent solution.
    ________________________________
    Gunnar Gestsson
    Microsoft Certified IT Professional
    Dynamics NAV MVP
    http://www.dynamics.is
    http://Objects4NAV.com
  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    thegunzo wrote:
    Hi Slawek.

    Vjeko did this in NAV using dotnet interop. Just look at his blog and the downloadable objects.
    Excellent solution.

    Ahhh.. haven't looked in attached code samples..... :oops:
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Options
    kinekine Member Posts: 12,562
    But we are in classic forum... I assume that it could be done through own automation, but it means own dll... :whistle:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.