Problem Adding Table Fields with CFront and C#

karstenrobertkarstenrobert Member Posts: 27
Dear all,

I'm trying to create new table fields for existing tables with cfrontdotnet and a c# program.

After trying and googling alot I was able to connect to a database and create new fields in a new table with this code.
	int Table;
            NavisionFieldType FieldType;
            Table = CFrontDotNet.Instance.CreateTableBegin(50007, "Item2", true);
            FieldType = NavisionFieldType.Option;
            CFrontDotNet.Instance.AddTableField(Table, 50000, "Testoption", FieldType, 4, "one,two,three,other",NavisionFieldClass.Normal);
            FieldType = NavisionFieldType.Text;
            CFrontDotNet.Instance.AddTableField(Table, 50030, "TestText2", FieldType, 30, "", NavisionFieldClass.Normal);
            CFrontDotNet.Instance.CreateTable(Table);
            CFrontDotNet.Instance.CreateTableEnd(Table);

My problem is that I don't want to create new tables really. I primarily want to add new fields to exisiting tables, especially option fields as you cannot create options fields from within navision by code.
So If I change the table ID to an existing it say that the tables already exists. And without using CFrontDotNet.Instance.CreateTable(Table); no error is raised but no modification is done to the table.

Is somebody able to provide some help??

Thanks in advance.
Karsten Frank
MCP - Dynamics NAV Developer

Comments

  • kinekine Member Posts: 12,562
    Why you need to do that from code? :-k
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • karstenrobertkarstenrobert Member Posts: 27
    This is nice when you transfer custom fields from one database to another.
    This is possible when you insert records in the field table, but this is not working with option fields as you cannot set the option strings.
    It would be nice to use the CFront functionality to do this as you can specifiy option strings here and this seems to work.
    But I would need to insert these fields in exisiting tables and not create new tables.
    Karsten Frank
    MCP - Dynamics NAV Developer
  • kinekine Member Posts: 12,562
    And how you will add C/AL code to these fields if there is some? (e.g. OnValidate)?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • karstenrobertkarstenrobert Member Posts: 27
    Basically you don't.
    You can use this procedure to test the conversion of customer databases while keeping all the raw data.
    The trigger code will most probably not work at all because of the version differences so you would need to handle that the traditional way.
    So not taking the trigger code for custom fields(50.000 .. 99999) to the standard database will not hurt you.

    So does somebody know if it is possible to just insert new fields in existing tables without interfering with existing fields by using CfrontDotnet?
    :?:
    Karsten Frank
    MCP - Dynamics NAV Developer
Sign In or Register to comment.