Export Item records via Xmlport using NAS

victor73victor73 Member Posts: 55
Hello,

I export item records from a Nav database to another Nav database using xmlports. Every 10 minutes all the modified items are exported to xml files using a NAS service. Everything works correct expect for the following fact: if a user is modifying an item and in the meantime the Nas service triggers (starts exporting the item recs) I receive the error that I attached.
Consequently some modifications are lost and of course the error is not nice to receive during modifications.
Can someone give me a suggestion on how to avoid the issue. At this moment we are bypassing the problem with a button on the form that the user must push to export the recs to xmlports: but as you can deduct our customer wants something automatic.
Thank you so much

Comments

  • kinekine Member Posts: 12,562
    Is the problem on the exporting NAV or on the Importing NAV? If on exporting - are you changing the records during export? What about using Tablelock to prevent changes during the export?
    If on importing, yes, of course, you are changing it and the user viewed the previous version of the record...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • victor73victor73 Member Posts: 55
    Hello Kine,
    thanks for your response, well, as I explained in my first message I have the problem while exporting nav items to xmlport, and yes the problem occurs just when exporting the info (by nas) and the user is modifying the rec. When yiu say Tablelock are you talking about "LockTable"? If so I tried using it just before calling the xmlport exporting as you can se in the following code lines:


    IF lRecCompany."Sync Output Xml Folder" <> '' THEN
    BEGIN

    // -- ITEM
    lRecItem.LOCKTABLE(TRUE);
    lRecItem.SETCURRENTKEY(ToSync);
    lRecItem.SETRANGE(ToSync, TRUE);
    IF lRecItem.FINDSET(TRUE,TRUE) THEN
    REPEAT
    lRecItem2 := lRecItem;
    lRecRecRef.OPEN(DATABASE::Item);
    lRecRecRef.GETTABLE(lRecItem);
    CreateXmlFile(lRecRecRef);
    lRecRecRef.CLOSE;
    UNTIL lRecItem.NEXT = 0;

    where the function CreateXmlFile(lRecRecRef) is a simple procedure that exports the rec to xmlport:

    ......
    DATABASE::Item:
    BEGIN
    iRecRecRef.SETTABLE(lRecItem);
    IF STRPOS(lTxtNewFileName,'__') = 0 THEN
    IF lFilNewFile.CREATE(lTxtNewFileName) THEN
    BEGIN
    lFilNewFile.CREATEOUTSTREAM(OStr);
    lXmlItemSyncEVC.SetItem(lRecItem);
    lXmlItemSyncEVC.SETDESTINATION(OStr);
    lXmlItemSyncEVC.EXPORT;
    lFilNewFile.CLOSE;
    EXIT(TRUE);
    END;
    END;
    .....
    but the error still occurs
    Please some other suggestion
    Thanks
  • kinekine Member Posts: 12,562
    Ehm... for me your code looks too complicated to just export the items in XML file. Why not use just xmlport over the Item table and run it once to export all what you need into the XML file?

    In you case, you will gate hundreds and hundreds XML files, one for each item.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • victor73victor73 Member Posts: 55
    Thanks,
    yes I know that i get an xml file for each record: it's a requirement for historical purposes, but we are trying to convince our cust to put in a single xml port all the modified items.
    Said this we are not focusing on the real problem dued to exporting to xml during user modifications. In fact as you suggest in your last response "Why not use just xmlport over the Item table and run it once to export all what you need into the XML file?" OK this will create one xml file for all my modifed items but if nas executes such functionality during a user is modifying the item table I receive the error and the last modifciations are lost.
    Any further suggestions?
    Thank you very much
  • kinekine Member Posts: 12,562
    I recommend to use client monitor to look for code changing the Item during the export. May be somewhere in the SetItem function of the xmlport. You have no reason to change the exported records, but it is somewhere modified...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.