Useful COM programming without class license ?

leelee Member Posts: 14
edited 2006-07-19 in Dynamics AX
Good morning!

I'm writing a web service and matching client in VB .NET.

I need to update some Axapta tables from the web service. I don't want to directly access the SQL tables (fine for reading but recId becomes a problem when writing new records).

I'd really like to do it properly and interface with Axapta using COM. Which requires some useful Axapta-side classes to interface with the tables in question.

The problem is I don't have the class license for Axapta !

So I guess what I'd love to know is :

1. Is there some existing class in Axapta that allows me to write arbitrary data to an arbitrary table (while automatically populating recId) ?

2. Does recId have to be unique across all tables in Axapta? By this I mean is it illegal for a record in, say InventTable to have the same recId as a record in PurchTable?

Or must recId be unique only within a table? Could I write a straight SQL statement which locks the table, looks at the most recent recId and adds 1 to it?

3. Any other ideas as to how I can achieve my goal ?

Thanks in advance for any help. Before long I hope to have enough knowledge to actually help other people with Axapta queries!

Lee

Comments

  • leelee Member Posts: 14
    OK I think I have come up with a valid solution. Via COM I'll call systemSequence.reserveValues(1) to reserve and get the next available recId (ie. so no other Axapta process uses that recId).

    Then I'll do an old-fashioned SQL insert using that recId.

    Could anyone comment on the validity of this plan ?
  • kashperukkashperuk Member Posts: 53
    The plan is good. but you have to understand well about what and where you have to insert. Meaning, that for an inserted record to be good and valid, you sometimes have to insert records into 2 or 3 tables, not just one.
    Vanya Kashperuk,
    My blog - http://kashperuk.blogspot.com
    MorphX IT in Russian - http://www.lulu.com/content/723888
    Inside Dynamics AX 4.0 in Russian - http://www.ozon.ru/context/detail/id/3714582
  • HarishHarish Member Posts: 172
    Hi Lee,

    If you are using Ax 3.0 pre SP5 and are trying to insert records into virtual company, please read ahead.

    A while ago I remember reading about a bug in Ax 3.0 (prior to SP5) involving reserveValues method.

    Apparently if you are trying to insert records into Ax virtual company table, recIDs were drawn not from the virtual company table but from the current company account.

    I believe this was fixed in SP5.

    Regards,
    Harish Mohanbabu
    Long way to go before I sleep..
  • leelee Member Posts: 14
    Thanks for the tip Harish. We seem to be only using SP1 !!

    If anyone else if trying to do the same thing, I got this code from Onno on MS's Dynamics forum. It lets you insert arbitrary code into an arbitrary table via COm and takes care of RecId automagically:
    Dim Axapta As Object
    Dim MyRecord As Object
    
    Set Axapta = CreateObject("AxaptaCOMConnector.Axapta")
    Axapta.Logon
    
    ‘ create an Axapta record
    Set MyRecord = Axapta.CreateRecord("MyTable")
    
    ‘ set fields of record
    MyRecord.InitValue
    MyRecord.Field("Name") = "MyName"
    MyRecord.Field("Address") = "MyAddress"
    
    ‘ insert the record
    MyRecord.Insert
    
Sign In or Register to comment.