How do I save the xmlfile from inside the XMLPort?

I have a scenario where a codeunit has been published, and all that the codeunit is doing is calling an xmlport that creates a purchase order based on the xml file being sent. Works like a charm and everybody is happy.
However, every now and again there are strange data errors in the order being created; but I see nothing in Table 38 that could make the errors, and the people sending the xml file say that they are sending the correct information. So in order to track where the problem arises, I would like to store every xml file that the xmlport is handling.

So does anybody have a solution to storing the file being handled from within the xmlport?
Don't just take my word for it, test it yourself

Answers

  • postsauravpostsaurav Member Posts: 708
    Hi,

    There are two things that you can do -
    1. Import Records from Xml To a Temp Table which is a copy of your standard table say purchase header with an additional field Error.
    2. The XMLPort Put the File Content in New Table, and a seprate codeunit keep on looking the records in new table and tries to insert record in table 38.
    3. If processed, delete the record from the New Table otherwise mark as Error To True.

    Second -
    1. You can have three folders instead of one named - incoming, Error, Processed.
    2. While Trying to Read the file if the Xmlport Generates an error message move the file to a Error Folder.
    3. IF Read is successful move the file to processed file.

    hope this helps.

    Thanks & Regards,
    Saurav Dhyani

    Do you Know this About NAV?


    Connect - Twitter | Facebook | Google + | YouTube

    Follow - Blog | Facebook Page | Google + Page
  • SunsetSunset Member Posts: 201
    Thanks for the suggestions, but I'm afraid that they don't solve my question.

    Option 1: I want the xml file itself, not the result of the insertion into table 38.
    Option 2: That would require me to have the file somewhere and I don't. having the file is what I want to achieve from the XMLPort.
    Don't just take my word for it, test it yourself
  • RockWithNAVRockWithNAV Member Posts: 1,139
    Hey Sunset,

    This is a very common Issue which you are facing and it happens when then there is in Integration done b/w two different Platforms.

    I want to know one thing, The Codeunit which you have published, How is it getting and recognizing the XML, I mean is there any specific path where your code checks and then execute the XML with its File name or some else process is going on.

    If there is no such process going and everything is going internally then you can ask them to dump the real XML on a certain path and give your exposed codeunit the name of the XML as a Parameter everytime they are using your it as a Webservice.

    This way you cant trace.
    Hope this Helps.

    Thanks
    Blog - https://rockwithnav.wordpress.com/
  • SunsetSunset Member Posts: 201
    The setup has been kept as simple as possible; so it's a codeunit with 1 function. That function has the XML as a parameter, and calls import directly. The XMLPort does virtually nothing, again to keep it as simple as possible, and have the table do all the validating.

    The codeunit in it's entirety
    OBJECT Codeunit 55004 ImportPurchaseOrder
    {
      OBJECT-PROPERTIES
      {
        Date=03-03-16;
        Time=12:00:00;
        Version List=WS1.00;
      }
      PROPERTIES
      {
        OnRun=BEGIN
              END;
    
      }
      CODE
      {
    
        PROCEDURE ImportPurchaseOrders@1080001(VAR purchaseOrdersXML@1080000 : XMLport 50001);
        BEGIN
          purchaseOrdersXML.IMPORT;
        END;
    
        BEGIN
        END.
      }
    }
    

    As it is a 3rd party software being wrapped by a Boomi integration engine, I am really hoping to avoid having them change the setup to find the problem.

    I could make a table that will store each node value from the file, but I would prefer do save the xml file itself.
    Don't just take my word for it, test it yourself
  • RockWithNAVRockWithNAV Member Posts: 1,139
    Hey Sunset,

    In that case i think you should simply put below code above purchaseOrdersXML.IMPORT;


    CreateFileName := 'PurchaseOrderXmlFIle' + '-' + FORMAT(DATE2DMY(TODAY,1))+FORMAT(DATE2DMY(TODAY,2))+FORMAT(DATE2DMY(TODAY,3)) + '.xml';
    FileName.CREATE('E:\FilePath\' + CreateFileName);
    FileName.CREATEOUTSTREAM(WriteStream);
    XMLPORT.EXPORT(50001,WriteStream);
    FileName.CLOSE;


    You can update the code as per your further need. This code will always save the file to the given location before importing and then you can validate later.

    Thanks

    Blog - https://rockwithnav.wordpress.com/
  • sooniorysooniory Member Posts: 2
    Hi RockWithNAV,
    i think it may not works by your way? the xmlport is a var parameter,the data of it is coming from outside(not in nav),so it seems that we can't use xmlport.export(50001,outstream) to put it in an outstream..
Sign In or Register to comment.