See first Import Invoices Example.
The Line Type tabs are used to import lines of data into the correct object. Line Type 1 is used for the main data object. Code in the Definition tab calls the LineType code with the ProcessLineType(1) function.
If you select First Line Contains Headers on the Definition tab, you can import the field names from the file. Click the
Add Fields button. (This is not available for ASCII files.) You will be prompted to enter the line number that contains the headers for this line type. Your input file can contain several header records. Alternately, you can enter the fields and offsets.
Validation
In the example Invoice import file, the Line Type 1 code starts by checking that the invoice date falls in the available periods, and is not blank.
If PeriodForDate(DateValue(DocumentDate.Value)) >= FirstAvailablePeriod("AR") and PeriodForDate(DateValue(DocumentDate.Value)) <= LastAvailablePeriod("AR") And PeriodForDate(DateValue(DocumentDate.Value)) <> 0 Then
It then checks if the Invoice is in a foreign currency, and if so, whether Foreign Sales are allowed:
If Not ApplicationSetting("CO\AllowForeignSales") and CurrencyCode.Value <> ApplicationSetting("CO\BaseCurrencyCode") Then
If these criteria are not met, an error message is displayed, and the line is not processed.
Insert Document
The Line Type 1 code then creates the document. To import an Invoice, you need to use the InsertType method. The example Import routine checks the DocumentClass field, and inserts the relevant type.
Select Case DocumentClass.Value Case "I" Data.InsertInvoice Case "C" Data.InsertCredit Case "Q" Data.InsertQuote Case "S" Data.InsertStandingInvoice End Select
Check Customer
In the example Import routine, the Line Type 1 code checks if the Customer is a foreign customer, and if so, checks whether foreign sales are allowed. If it is an allowed foreign customer, it sets the FX rate details for the Invoice. It then sets the Customer Code for the Invoice.
Dim Customer as ObjectCustomer = CreateObject("Accredo.ARCustomerData")Customer.FindExact(CustomerCode.Value)If Customer.CurrencyCode <> ApplicationSetting("CO\BaseCurrencyCode") Then If Not ApplicationSetting("CO\AllowForeignSales") Then Error "Foreign Sales not allowed, cannot import customer with currency " & Customer.CurrencyCode Else If Not ApplicationSetting("CO\UseExchangeRateTable") Then Data.FXRateCache.Insert Data.FXRateCache.CurrencyCode = Customer.CurrencyCode Data.FXRateCache.ExchangeRate = ExchangeRate.Value Else Data.RateType = RateType.Value End If Data.CustomerCode = CustomerCode.Value Data.ExchangeRate = ExchangeRate.Value End IfElse Data.CustomerCode = CustomerCode.ValueEnd If
Import Fields
The example Import routine Line Type 1 then imports the other fields. Use the InInvoiceData Documentation for a list of properties in the Invoice object, to map the fields in your import file to the InInvoiceData properties. Note that some of the InInvoiceData properties are required. You cannot import the Invoice without these fields. Also, some of the InInvoiceData properties are read-only. You cannot import these properties.
You can do further validation on fields. The example Import routine checks date fields to ensure they are not blank. For example:
If DocumentDate.Value <> "" Then Data.DocumentDate = DateValue(DocumentDate.Value)
It also sets the Invoice Period to the period the Invoice Date occurs in. Data.PeriodID = PeriodForDate(Data.DocumentDate)
It checks if Manual Numbering is allowed, and if so it sets the Document Number. If ApplicationSetting("IN\AllowManualNumbering") Then Data.DocumentNo = DocumentNo.Value End If
It then InInvoiceData properties from the fields mapped from the Import File.
Data.OrderNo = OrderNo.Value Data.SalesPersonCode = SalesPersonCode.Value ....
Ensure all required fields are set, and that all relevant fields in the Import file are mapped and set.