Importing a XML sales order

BatemanBateman Member Posts: 6
Hi all,

as part of my diploma thesis I'm preparing some student exercises dealing with Navision 4.0 data import and export. One of the exercises is creating a XMLport for a more complex XML document - a sales order. Setting up the XMLport and importing the data into two new tables (eg. SalesHeaderTmp, SalesLineTmp) isn't hard, but I wonder if it is possible to insert the data into the "real" Sales Header and Sales Line tables (36, 37). So far I didn't have any luck getting that to work. I've mapped all tags of the XML to the corresponding table fields and filled up the missing fields (eg. document type) with a few C/AL statements. When I try to run my XMLport I always get the following message: "The sales header does not exist. Identification fields and values: Document Type='order',No.='[An order no. from my xml]'

Thanks for any suggestions and hints or even a better solution!

René

Answers

  • bbrownbbrown Member Posts: 3,268
    Turn on the debugger (breakpoints off) and run your xmlport. This should indicate where the error is occurring. The error is probably caused by an attempt to modify the new sales header prior to inserting it. It may be a modify statement in your code or the result of a field.validate that you are calling.
    There are no bugs - only undocumented features.
  • DenSterDenSter Member Posts: 8,307
    Yeah that has to be a MODIFY statement in your code. XMLPorts are designed to insert records (AFAIK you can't modify records with an XMLPort), so that should not be a message that just pops up by running one. I've had to set the XMLPort dataitem to be a temporary record variable and 'manually' INSERT/MODIFY it into the 'real' table, but that message is most likely because of a MODIFY of a record that does not exist.
  • Michael_SchumacherMichael_Schumacher Member Posts: 81
    Bateman wrote:
    When I try to run my XMLport I always get the following message: "The sales header does not exist. Identification fields and values: Document Type='order',No.='[An order no. from my xml]'

    Hi René,
    In fact I'm working on xml-ports for converting a foreign program to navision.
    I went through this message also. I think it comes from inserting a sales line....
    Try this:
    in the properties of the tag where you defined table sales line set LinkTableForceInsert to yes and LinkTable to the variable you definded for Sales header. In C/AL code of salesHeader - OnInitRecord you shoud have set Document type to order so that the order header will be created as soon as the xml-port retrieves the order number, read in all the order lines and then goes through the rest of the header elements.
    when orderlines are inserted the validation of order number finds the header (doesn't matter that there is only the number and the document typ) and doesn't fail anymore.

    hope that helps
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • DenSterDenSter Member Posts: 8,307
    Right, that is a very good point. Before you set any properties, look at the table element's triggers and make sure you set the document type at the right moment. If I were to guess, I would try the OnBeforeInsert trigger first.
  • Michael_SchumacherMichael_Schumacher Member Posts: 81
    DenSter wrote:
    Right, that is a very good point. Before you set any properties, look at the table element's triggers and make sure you set the document type at the right moment. If I were to guess, I would try the OnBeforeInsert trigger first.

    This is to late when you want the document type to be correct in the moment when the header is insertet. this insertion happens at the moment when the first orderline is to be insertet, if you have the property LinkTableForceInsert set to yes.....

    This OnBeforeInsertRecord trigger is triggert after insertion of the lines and after assigning all values from elements and attributes inside the element which is assigned to the header, and not when this forced insert takes place.

    the assignment of documenttype has to take place either in the OnAfterInitRecord trigger of the header or in a trigger of an element or attribute which comes before the first orderline element.

    I stumbled into that trap myself in the first tries :-$
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • DenSterDenSter Member Posts: 8,307
    really... that is interesting. You'd think that OnBeforeInsert would run before inserting... #-o

    Thanks for the tip.
  • BatemanBateman Member Posts: 6
    wow... thank you for all the answers. The right LinkTable settings and putting code into the OnBeforeInsert trigger definitely helped. It's also useful to turn off default fields validation and validate only necessary fields manually (via property or code). Couldn't tell what finally made it work though, too much trial and error involved. :)
  • Michael_SchumacherMichael_Schumacher Member Posts: 81
    moin moin Bateman,

    It's not so bad to let the validation in default setting.

    You always should try with data, that normally comes in and when there is an error because of validation, you get this and can handle it, eg in reading the value in a variable and put it in the right field with code, after prerequisites are fulfilled.
    If you shut off the default, maybe you get this error much later, when s.o. tries to use this data, because you didn't think of a possible validation error. :whistle:

    So, when your Problem is solved, please remember the [solved] statement in original posting..... :wink:
    regards,
    Michael Schumacher

    oh, what day is it? Backup day. OK, let's dump all data to /dev/nul ;-)
  • BatemanBateman Member Posts: 6
    I can imagine that disabling the validation isn't a good idea in a live business environment, but since it is just for a student exercise focusing on integration and xml, it's an ok solution.
Sign In or Register to comment.