mibuso.com

Microsoft Business Solutions online community
It is currently Sat May 18, 2013 5:26 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Dataport Duplicate OnAfterImportRecord processing
PostPosted: Thu Jul 19, 2012 4:44 pm 
Offline

Joined: Fri Mar 23, 2007 9:10 pm
Posts: 32
Location: United States
Country: United States (us)
Hi all,

I am working in 5.0 importing order information. The file I am importing is comma delimited and contains both header and line information in each record. The current method is for the user to create their order header with customer info and then launch my dataport from the function menu. In this case, I have decided to handle all of the processing myself. I'm just using the dataport to get the fields into global variables that I have created. Then I insert/modify/etc as I see fit. I am using Sales Header as my dataitem even though the record I'm working with already exists. My problem is that it seems the OnAfterImportRecord code fires twice no matter what. I have tried turning autosave and autoupdate off, but when I do, I get an error that my sales line record is locked. I have come up with a workaround where I check the sales line table to see if my item already exists but I don't like it in that it would mishandle an import where the same item was listed multiple times. My workaround is shown in the code below but the bottom line is that the trigger fires twice per line and I can't figure out how to fix it for the long term. This dataport is based on another with a similar function AND the same problem so there are several unused globals listed. Any thought or ideas would be greatly appreciated:

Code: Select all
OBJECT Dataport 50127 New Order Import
{
  OBJECT-PROPERTIES
  {
    Date=07/19/12;
    Time=[ 8:59:34 AM];
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
    FieldStartDelimiter=<None>;
    FieldEndDelimiter=<None>;
    OnPreDataport=BEGIN
                    sh.SETRANGE("No.", Orderno);
                    IF NOT sh.FIND('-') THEN
                     ERROR('Sales Header not found.');
                    PO := FALSE;
                    lineno := 0;
                    qty := 1;
                  END;

  }
  DATAITEMS
  {
    { PROPERTIES
      {
        DataItemTable=Table36;
        DataItemVarName=Salesheader;
        AutoSave=Yes;
        AutoUpdate=Yes;
        OnAfterImportRecord=BEGIN
                              IF PO = FALSE THEN BEGIN
                               sh."External Document No." := PONo;
                               sh."Requested Delivery Date" := deliverydate;
                               sh."Ship-to Name" := addrname;
                               sh."Ship-to Address" := addr1;
                               sh."Ship-to Address 2" := addr2;
                               sh."Ship-to City" := addrcity;
                               sh."Ship-to County" := addrstate;
                               sh."Ship-to Post Code" := addrzip;
                               sh.Imported := TRUE;
                               sh.MODIFY;
                               PO := TRUE;
                              END;

                              sl.SETRANGE("Document No.",Orderno);
                              sl.SETRANGE("No.",itemno);
                              IF NOT sl.FIND('-') THEN BEGIN
                               lineno := lineno + 10000;
                               sl.INIT;
                               sl."Document Type" := sl."Document Type"::Order;
                               sl."Line No." := lineno;
                               sl.VALIDATE("Document No.",Orderno);
                               sl.VALIDATE(Type,sl.Type::Item);
                               sl.fromimport(FALSE);
                               sl.fromimport(TRUE);
                               item.SETRANGE("No.",itemno);
                               IF NOT item.FIND('-') THEN
                                ERROR(Text02,itemno);
                               sl.VALIDATE("No.",itemno);
                               sl.VALIDATE(Quantity,qty);
                               sl."Customer Item No." := Stockno;
                               sl."Modified Time" := CURRENTDATETIME;
                               sl.INSERT;
                              END;
                            END;

      }
      FIELDS
      {
        {      ;     ;PONo                 }
        {      ;     ;desc1                }
        {      ;     ;itemno               }
        {      ;     ;qty                  }
        {      ;     ;desc2                }
        {      ;     ;deliverydate         }
        {      ;     ;addrname             }
        {      ;     ;addr1                }
        {      ;     ;addr2                }
        {      ;     ;addrcity             }
        {      ;     ;addrzip              }
      }
       }
  }
  REQUESTFORM
  {
    PROPERTIES
    {
      Width=9020;
      Height=3410;
    }
    CONTROLS
    {
    }
  }
  CODE
  {
    VAR
      line@1000000004 : Text[255];
      Orderno@1000000003 : Code[20];
      i@1000000002 : Integer;
      Position@1000000001 : Integer;
      Stockno@1000000005 : Code[20];
      serialno@1000000006 : Code[20];
      lserialno@1000000007 : Code[20];
      desc1@1000000008 : Text[75];
      desc2@1000000009 : Text[75];
      PONo@1000000010 : Code[20];
      ManufacturingNo@1000000011 : Code[20];
      ManufacturingCode@1000000012 : Code[20];
      PO@1000000013 : Boolean;
      sl@1000000014 : Record 37;
      sh@1000000015 : Record 36;
      sp@1000000016 : Record 7002;
      lineno@1000000000 : Integer;
      item@1000000017 : Record 27;
      Text01@1000000018 : TextConst 'ENU=Customer Item %1 not found in the Sales Price table.';
      itemno@1000000019 : Code[20];
      qty@1000000020 : Integer;
      Text02@1000000021 : TextConst 'ENU=Item %1 not found in the item table.';
      sn@1000000022 : Record 50024;
      deliverydate@1000000023 : Date;
      addrname@1000000024 : Text[50];
      addr1@1000000025 : Text[50];
      addr2@1000000026 : Text[50];
      addrcity@1000000027 : Text[30];
      addrstate@1000000028 : Text[30];
      addrzip@1000000029 : Text[20];

    PROCEDURE SetOrderNo@1000000000("No."@1000000000 : Code[20]);
    BEGIN
      Orderno := "No.";
    END;

    BEGIN
    END.
  }
}



Thanks in advance!

_________________
Jack Littlejohn
Clemson, SC


Top
 Profile  
 
 Post subject: Re: Dataport Duplicate OnAfterImportRecord processing
PostPosted: Thu Jul 19, 2012 5:54 pm 
Offline
MVP Microsoft Dynamics NAV
Site Supporter

Joined: Fri Jun 06, 2003 9:01 pm
Posts: 6977
Location: L.I., New York
Country: United States (us)
I would use the document type in your setranges.
Quote:
sh.SETRANGE("No.", Orderno);
IF NOT sh.FIND('-') THEN


I've done somthing like this in the past for Credits. Where the user creates the header and we import the lines. I use the Sales Line as the dataitem since the header already exists.

On my function button I have this code:
Code: Select all
OnPush()
CLEAR(GetItemFromFile);
GetItemFromFile.SetGlobalParameters(0,"Document Type","No.");
GetItemFromFile.RUNMODAL;


Globals
Name DataType Subtype Length
Code: Select all
GetItemFromFile->Dataport->Internet Returns Import //basically my dataport name


My dataport is like this, where I have created a function to get the info from the header like doc no & type called "SetGlobalParameters". then I can use those values to import lines into the header that I'm working on.:

Code: Select all
OnPreDataItem()
ReturnLineNo := 0;

OnAfterImportRecord()
ReturnLineNo := ReturnLineNo + 10000;
"Sales Line"."Document Type" := "Sales Line"."Document Type"::"Credit Memo";
"Sales Line".VALIDATE("Document No.",vDocumentNo);
"Sales Line".VALIDATE("Line No.",ReturnLineNo);
"Sales Line".Type := "Sales Line".Type::Item;
"Sales Line".VALIDATE("No.",ReturnItemNo);
"Sales Line".VALIDATE(Quantity,ReturnQty);
"Sales Line"."Return Reason Code" := ReturnBoxCode;

SetGlobalParameters(DocSubType : Integer;DocType : Integer;DocNo : Code[20])
vOrderType := DocSubType;
vDocumentType := DocType;
vDocumentNo := DocNo


Works Great! If you think the trigger if firing more than once perhaps it's running for every document type option since you're not SETRANGE-ing "order" and you can always throw in a MESSAGE('Whatever'); in your code so you can see what & when it's firing.

_________________
Harry Ruiz
http://www.cosmeticsolutions.com
http://www.autismspeaks.org


Top
 Profile E-mail WWW  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot], jglathe and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: