am i stupid or does navision suck?

I can't figure out what the hell I'm doing wrong with Navision. The documentation seems terrible and the example code is poor at best.

I'm trying to just insert a record into a table and I'm not getting any kind of error message that is meaningful to me. Just a "You cannot make any changes in the database from this trigger" which doesn't mean anything to me.

The code I've got is written using Python for Windows. The second last line is where things go wrong in Navision.

Anyone have any idea what's wrong here?

def test1():
cf = win32com.client.Dispatch("cfront.cfrontctrl.1")
#cf.HideError = True # turn off dialog errors

cf.ConnectServer('navision', 'tcp')
print "Connect status:", cf.LastError()

cf.OpenCompany('GAP Adventures Play')
print "Open Company:", cf.LastError()

tableNo = cf.TableNo('Sales Line')
print "Table No:", tableNo
print "Table Last Error:", cf.LastError()

resultCode, hTable = cf.OpenTable( 0, tableNo )
print "ResultCode [%r] -- TableHandle [%r]" % (resultCode, hTable)

hRec = cf.AllocRec(hTable)
cf.InitRec(hTable, hRec)

print "Record: %r" % hRec

docTypeID = cf.FieldNo( hTable, 'Document Type')
docNoID = cf.FieldNo( hTable, 'Document No.')
lineNoID = cf.FieldNo( hTable, 'Line No.')

print "Document Type fieldNo: %d" % docTypeID
print "Document No. fieldNo: %d" % docNoID
print "Line No. fieldNo: %d" % lineNoID

cf.AssignField( hTable, hRec, docTypeID, 1)
cf.AssignField( hTable, hRec, docNoID, 943924)
cf.AssignField( hTable, hRec, lineNoID, 10000)

result = cf.InsertRec(hTable, hRec)
print "Insert result: %r" % result
  • If you didn't use the search button on this forum I guess it's the first one...
  • Thanks! Your reply was completely useless!

    So what am I doing wrong here? I _have_ searched for "You cannot make changes..." but I haven't found anything that has helped.

    The only thread I can find is this one:

    http://www.mbsonline.org/forum/topic.asp?TOPIC_ID=2837&SearchTerms=from+this+trigger

    And it's not terribly useful either.

    vic
  • I dunno...I think it might be you. [;)]
  • Hint #2: You need to begin a transaction before you can write to the db...
  • hi all,

    Going back over my original 2 posts - i've just been having an extremely frustrating time getting any kind of support from our Navision supplier with respect to getting some functioning code.

    I apologize to everyone (i know it's late), but i am sorry for being an ass.

    How do I go about setting up transactions?

    For that matter, where are you guys looking for reference code when you have problems? The only thing that seems to be useful to mee is this PDF called "w1w1cfront.pdf" witha title "C/Front reference guide".

    Unfortunately, my navision supplier can't help me out in compiling any of these samples. Although I am a ninja on UNIX, I am a moron on Windows and I can't figure out how to do simple compiles.
  • quote:
    I dunno...I think it might be you. [;)]

    Originally posted by speetz - 2004 Oct 13 :  20:48:50



    Com'on guys, be nice to this guy.

    Victor, before you say Navision "suck", understand the whole situation before you say something "suck". Cause saying stuff "suck" will not earn you any help from the people in this forum.

    There are a few things you need to mention before anyone can help you.

    Looks like you're trying to insert something into the sales line or purchase line using C/FRONT.

    1. What is the business problem you're trying to solve?
    2. Is the referencing purchase/sales header properly created already?
    3. When you do this, do you know you cannot validate fields in Navision?
  • Thanks,

    1. What is the business problem you're trying to solve?

    I have a project where I need to create, update and read records between Navision and our own internal software. Our Navision rep suggested using the COM interface.

    My requirements will have me hitting a variety of tables and inserting/update/reading records from them at any given time.

    2. Is the referencing purchase/sales header properly created already?

    I have no idea what you're talking about. All I've been told by our Navision rep is that the code I have "should work". How do I go about creating a purchase/sales header.

    3. When you do this, do you know you cannot validate fields in Navision?

    Again - I have no idea what you're talking about. What validation is required? Isn't there some way to just create a record in table a'la SQL?

    vic
  • The documentation for C/Front is relatively scarce, because:

    1) You are expected to posess a mastery of the C/SIDE development environment.
    2) You can do a lot of damage in a very short while if you do not understand the C/SIDE environment.

    That said, there are a few places to look for examples:
    • sample.c is a C-language demo of C/FRONT dll features...

    • cfront.chm is a WinHelp file for the C/FRONT ocx...

    • cfront.xls is an Excel spreadsheet with VBA code examples...
    To enable writing to the database, you must begin a write transaction. Then, when all writes are finished, you must end the write transaction. Of course, if an error occurs, you must abort the write transaction.

    In your example above, this would look something like this:

    cf.BWT()
    result = cf.InsertRec(hTable, hRec)
    if (result)
    cf.EWT()
    else
    cf.AWT()
    I must caution you again, however, that there are all sorts of issues that haven't been dealt with here, especially when inserting Sales Lines into a Navision db.

    Proceed with care, and good luck!
  • quote:
    Thanks,

    1. What is the business problem you're trying to solve?

    I have a project where I need to create, update and read records between Navision and our own internal software. Our Navision rep suggested using the COM interface.

    My requirements will have me hitting a variety of tables and inserting/update/reading records from them at any given time.

    2. Is the referencing purchase/sales header properly created already?

    I have no idea what you're talking about. All I've been told by our Navision rep is that the code I have "should work". How do I go about creating a purchase/sales header.

    3. When you do this, do you know you cannot validate fields in Navision?

    Again - I have no idea what you're talking about. What validation is required? Isn't there some way to just create a record in table a'la SQL?

    vic

    Originally posted by victoratgap - 2004 Oct 13 :  23:29:39



    Ok... If you don't know what I'm talking about, then it's probably better that you don't start any project where you have to insert/modify/delete data into the Navision tables.

    Yes, technically, you can do anything in the SQL tables, however, by doing so, you might cause serious irreversable damage to the Navision data.

    Try learning Navision first, especially the programming portion , then you'll understand more on how to interface with it.

  • quote:

    I'm trying to just insert a record into a table and I'm not getting any kind of error message that is meaningful to me. Just a "You cannot make any changes in the database from this trigger" which doesn't mean anything to me.


    I think Victor's opening diatribe contains a good point though. It is a terrible and unrelated error message (borrowed from a different error situation altogether within c/side) for such a simple mistake.

    I think it should be changed to something like "You cannot make database modifications because you have not yet begun a transaction."
Related
Recommended