I need advise about sale's order and DATAPORT.

Hi!

I have got this task to export items(its done) and import orders and orderdetails into navision (3.7).

I need some advise about import, my first idea was to use XMLPORT but since 3.7 not including XMLPORT so think that i am going to use the Dataport, is it bad idea!?

Hi there,

I would say that depends on the structure of the files You want to import.

If the file contains more than 1 SO, then it have to have all headers before any lines, in order to be able to import the whole file.
e.g. If the file is structured as “Header1”, then “Lines1”, then “Header2”, then “Lines2” etc., I would expect a dataport to be a too simple tool for this, since a dataport can’t loop through the DataItems more than once.

A report, designed on Integer, can do the trick for You, if the file-structure are not “DataPort-compatible”.
Set the Integer-DataItem to only run through once (DataItemTableView = SORTING(Number) WHERE(Number=CONST(1)))
Define a variable of type File.
OnAfterGetRecord, write something like this…
REPEAT
FileVar.READ
… Do the processing …
UNTIL FileVar.POS = FileVar.LEN;

I’m pretty sure that You will be able to handle the XML-format through the report-solution, but I have absolutely no clue on how, as I’ve never tried it myself.
(Someone else in here have though… I would expect)

I have an “import-report” laying around somewhere, that I can dig up and send to You, to give You a more detailed insight in what I try to explain. [:)]

Hi,

Thanks for your idea, I believe that I am going for yout first suggestion.

I shall be gratefull if you send me that.

Best regards

Nasser

.NET developer

Hi Nasser,

I’ll dig it up, and send it to You.

Either You’ll have to give me an e-mail I can send it to, or You’ll have to contact me through MSN-messenger at some point I’m online.

The advantage of XML, is that it is the technology going forward, so it may be worth a technical upgrade to 4.00 for that.

Good point David.

Hi there,

You can still use dataport to import sales orders from external sources. But you need to ask this question first. Do you receive one or two files (header and line) from your other party. We import many vendor csv invoices into Purchase Line and Purchase Header the same way we import csv orders from large department stores (translated from EDI) into Sales Header and Sales Line. In most cases you may receive only a single flat file from your trading partners, which is highly denormalized and has field data common to both Sales Header and Sales Line. The DataItem in your dataport should be Sales Line which should have the same granularity as your flat file for line-level iteration. As you cannot import child record (Sales Line) before the parent (Sales Header), you need to create the Sales Header record first as soon as the dataport detects a new Document No. from the imported data (in my example this is going to be your customer order no. that you need to check). Often you will also want to enter your customer order no. into in the External Document No. of your header.

The best place to perform this check is in the OnAfterImportRecord() trigger (variables prefixed with VC are fields specific to an application you are importing FROM):

Sales Line - OnAfterImportRecord()
{

CurrExtDocNo := “VC Purchase Order No.”;

IF IsNewDocNo THEN BEGIN
CreateSalesHeader;
ModifySalesHeader; // Similar step as if you would have created a Sales Order manually
END;

SetUpSalesLine;
LastExtDocNo := CurrExtDocNo;

}

IsNewDocNo() : Boolean
{

IF CurrExtDocNo <> LastExtDocNo THEN
EXIT(TRUE)
ELSE
EXIT(FALSE);

}

SetUpSalesLine()

{

GetSalesHeader;

WITH “Sales Line” DO BEGIN // Only required fields are mapped
“Document Type” := SalesHeader.“Document Type”::Order;
“Document No.” := SalesHeader.“No.”;
“Line No.” := NextLineNo;
VALIDATE(“Sell-to Customer No.”,Cust.“No.”);
Type := Type::Item;
ItemIdentifier.GET(“VC Bar Code”);
VALIDATE(“No.”,ItemIdentifier.“Item No.”);
VALIDATE(“Variant Code”,ItemIdentifier.“Variant Code”);
VALIDATE(Quantity,“VC Store Quantity”);
VALIDATE(“Unit Price”,“VC Unit Price”);
IF ROUND(“Unit Price”,0.01,’=’) <> “VC Unit Price” THEN
MESSAGE(‘The Unit Price on EDI Order No. %1 is different from the Sales Price set up in NAV.’,“VC Purchase Order No.”);
Item.GET(ItemIdentifier.“Item No.”);
IF ROUND(Item.“Unit List Price”,0.01,’=’) <> “VC Retail Unit Price” THEN
MESSAGE(‘The Unit List Price on EDI Order No. %1 is different from the Sales Price set up in NAV.’,“VC Purchase Order No.”);
VALIDATE(“Shipping Agent Code”,SalesHeader.“Shipping Agent Code”);
VALIDATE(“Shipping Agent Service Code”,SalesHeader.“Shipping Agent Service Code”);
END;

}

Hope you get the idea.

Scott

Hi Sott,

I am a little bit CONFUSED, probably this my own fault.

That is the situation

I have to develope a .NET application that will coomunicate with Navision by using MSMQ and NAS, I did managed to Exporting products(Items) from Navision, the other job is to importing Sales order into Navison, I thought that I could use XMLPORT since the Navision that I have to use is 3.7, and I can not use XMLPORT.

Is there other ways to insert Orders into the Navision by using CODEUNIT?

My Idea is to made a XML file that including my Saleorders and Saleorderlines than I call my Codeunit(this will happend from my .NET ) to read this file and insert these into Sales Header andSales Line without massing with these

tables,

Any Idea or suggestion!?

Yes, but why would you want to do that? Do you really have to use XML? How about CSV or TXT? Sorry I do the majority of import/export using Dataport, not XMLPort. There are far too many fields in the Sales Header and Sales Line tables for you to do it in codeunit. Yes, it is technically feasible but you’d be reinventing the wheel since you can call DATAPORT.RUN from any NAV object. Otherwise you would have to do something like that:

ImportSalesOrders()

{

ImportFile.CREATE(‘C:\Temp\SO.csv’);

ImportFile.TEXTMODE(TRUE);

ImportFile.CREATEINSTREAM(ImportFileStream);

//Set up two 2-D arrays (one for rows one for columns)

//Read file into a Rows[] array

//Start two while loops

//Split each row into Columns[] array (I would also need to use a routine I previously wrote to split a row w/ delimiters into field values in an array)

//Assign Column array[] value to SalesHeader.“Some Field Name”

//Validate each field;

//End loops

ImportFile.CLOSE;

}

Sorry, I don’t understand the last part about messing with these tables.

Hi,

My question about messing with tables is the following, can I insert values into to tables from my CODEUNIT without messing with Navision logic!?

I supose that you are right, but how can I call a DATAPORT from my .NET app!?

I try to use DATAPORT.RUNMODAL(DP_ID, false); inside a CODEUNIT that I call from my .NET app( by help of MSMQ and NAS) but some times it works and some times not, when I look in my Event logs I se the following messag about my NAS service

You cannot use C/AL variables of type DATAPORT when running the Microsoft Business Solutions-Navision Application Server.

Is there any DATAPORT that I can use as template to do import of sales order!?

I have a DATAPORT that

OK, this changes things a little. (It always takes time in these threads for people to tell the whole story, not sure why that is though).

Anyway, in reply to your original request to Dataport into Navision, I suggested XML as an alternative. BUT if you plan to use .NET and NAS, then I would completely rule out Dataports. You really should go the XML route.

Hi David,

I am sorry if I did not explained my problem/task in details sooner.

Are you meaninig that I have to use XMLPORT!? that was my first idea but when I see that our client running on 3.7( no XMLPORT her[:S]) so I had to change my strategy.

I thought that I can use DATAPART from my CODEUNIT, but it seems impossible. look at the following message from my EVENTLOG

You cannot use C/AL variables of type DATAPORT when running the Microsoft Business Solutions-Navision Application Server

Is there any other way to use XML with CODEUNIT!? I tried to send a large XML string from my .NET ( by MSMQ), but I got some error message( I do not remember the exact content but it was some thing about the length that was larger then allowed, it seems that the limit was about 250 CHAR).

I have this question, suppose that I can manage to get my XML into my CODEUNIT, how can insert data into Sales Header and Sales line without massing with database, I believe that it is not that easy.

Are you on support? If so then just upgrade to 4.00 SP3 or ver 5.000 executables.

Hi David,

It is almost impossible, our client do not want to use money or time to upgrade.

That makes it tough. Are they paying the Microsoft Enhancement plan fees? If so then they will have access to the latest version, whih includes XML. The EXE upgrade is simple, and they can probably do it themselves. I think that in the end they will probably spend unnecessary money paying you to do work arounds, so in the end the upgrade may be a cheaper solution.

On the other hand if they are not on the enhancement plan then you are out of luck.