Adding a new field dynamically to a table

navvynavvy Member Posts: 79
Hi,

I have to add a new field to several tables on different NAV installations. Is there a way to add these fields "dynamically" ?
Is it possible to put CAL code "dynamically" behind a table (e.g. on OnInsert()) ?

Thanks in advance,
navvy
navvy
Freelance Developer

Comments

  • lvanvugtlvanvugt Member Posts: 774
    No, C/SIDE does not allow that.

    There might be work-arounds on a NAV SQL Server setup by writing SLQ code (etc.), but I guess that's not what you are looking for.
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • DuikmeesterDuikmeester Member Posts: 304
    You can do an insert in the Field table as long you have the appropiate license and use the correct field numbers.
    Field.INIT;
    Field.TableNo := DATABASE::Currency;
    Field."No." := 11002002;
    Field.FieldName := 'My Field';
    Field.Class := Field.Class::Normal;
    Field.Type := Field.Type::Boolean;
    Field.Enabled := TRUE;
    Field.INSERT;
    
  • lvanvugtlvanvugt Member Posts: 774
    Maybe I thinking wrong (and reading the original post wrong), but that's not adding a field to a tbale, but populating existing fields with values.

    Right?
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • DuikmeesterDuikmeester Member Posts: 304
    lvanvugt wrote:
    Maybe I thinking wrong (and reading the original post wrong), but that's not adding a field to a tbale, but populating existing fields with values.

    Right?

    Did you try it, my sample code? This will create an actual NEW field in Table 4...
  • lvanvugtlvanvugt Member Posts: 774
    YOU ARE RIGHT. Learned something again. Thanx!
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • matttraxmatttrax Member Posts: 2,309
    You can do an insert in the Field table as long you have the appropiate license and use the correct field numbers.

    I disagree with this approach completely. Yes it can be done, but why would you?

    You still have to get that code on to the customer database somehow. So you're importing an object regardless. How could writing code to add a field possibly save time over just simply adding the field by hand?

    I learned a long time ago that NAV wants you to do things in a certain way. That doesn't mean don't find ways to improve processes, that's what NAV is about, but when it comes to the basics, like adding a field, stick to the usual method.
  • navvynavvy Member Posts: 79
    Thank you for all your answers ! :)

    Because I also have to put CAL code behind the tables (e.g. on OnInsert()), I think I will add the new fields by hand.

    navvy
    navvy
    Freelance Developer
  • David_SingletonDavid_Singleton Member Posts: 5,479
    matttrax wrote:
    You can do an insert in the Field table as long you have the appropiate license and use the correct field numbers.

    I disagree with this approach completely. Yes it can be done, but why would you?

    You still have to get that code on to the customer database somehow. So you're importing an object regardless. How could writing code to add a field possibly save time over just simply adding the field by hand?

    I learned a long time ago that NAV wants you to do things in a certain way. That doesn't mean don't find ways to improve processes, that's what NAV is about, but when it comes to the basics, like adding a field, stick to the usual method.


    :thumbsup: =D>
    David Singleton
  • idiotidiot Member Posts: 651
    Did you try it, my sample code? This will create an actual NEW field in Table 4...

    Does using code to add field require a re-compile of the table?
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • DuikmeesterDuikmeester Member Posts: 304
    idiot wrote:
    Does using code to add field require a re-compile of the table?

    Table does not seem to have to be recompiled, the modified time/date/mark however will change.

    P.S: I have never used this in real world situation, I just know that this works...
Sign In or Register to comment.