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. } }
Comments
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:
Globals
Name DataType Subtype Length
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.:
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.
http://www.BiloBeauty.com
http://www.autismspeaks.org