Hi, I want to import a .txt file on click of a button on the sales order form. Sales order number will be auto generated & when i click on the import button it should fill up other fields of sales header. The data of the .txt file should be visible on the form once i click the import button. Thanks in advance, vikas
Use Quote to Sales Order routine. It will help you. Regards
Hi, The .txt file will contain all the other fields except Order No. When i click the import button on the sales order form it should populate the data on the form except the order no, because order no. exist since it’s a auto generated NO. please suggest Vikas
Vikas Copy and Paste this into the documentation section if it helps This code is not complete and is untested In code you will need to open the file. Read in each line identify the values and populate the fields. This is an example your txt file will need to be constructed so you can do this. NAME:Mr Harry Potter ADD1:1 The High Street ADD2: ADD3:Oxfordshire ADD4:Quainton ZIP:OX2 222 COUNTRY:UK TEL:01234456456 Create a Codeunit with a function to pass in and set the File Name C/AL Globals NAME TYPE SalesHeader Record ‘Sales Header’ SOFile File FileName Text 250 TextLine Text 50 FieldID Text 30 Found Integer // Open the file // You will need to have set the FileName before running the codeunit IF FileName = ‘’ THEN ERROR(‘No file to Import’); CLEAR(SOFile); SOFile.TEXTMODE := TRUE; SOFile.OPEN(FileName); // Create a Sales Order: // Always Set the Salesheader.“No.” to blank as INIT does not clear Primary Key fields SalesHeader.INIT; SalesHeader.“Document Type” = SalesHeader.“Document Type”::Order; SalesHeader.“No.” := ‘’; SalesHeader.INSERT(TRUE); // While not end of file loop and Read each line into a variable WHILE SOFile.POS <> SOFile.LEN DO BEGIN CLEAR(TextLine); CLEAR(FieldID); SOFile.READ(TextLine); // Find the position of the Token Found := STRPOS(TextLine,’:’); // Lets look at ‘NAME:Mr Harry Potter’ Found = 5 // See if we have a value to assign and not a blank field IF (Found <> 0)and (STRLEN(TextLine) > Found + 1) THEN BEGIN FieldID := COPYSTR(TextLine,1,Found - 1); // Now FieldID = ‘NAME’ 1-4 TextLine := COPYSTR(TextLine,Found + 1) // Now TextLine = ‘Mr Harry Potter’ 6 to STRLEN // Now constuct a case to Assign the Values to the fields CASE FildID OF ‘NAME’: SalesHeader.“Name” := TextLine; ‘ADD1’: SalesHeader.“Address” := TextLine; END; END; END; // We want to be able to see the file from (Not on) the Sales Header Add a Field to the Sales Header Table “File Name” Text 250 Editable NO SalesHeader.“File Name” := FileName; SalesHeader.MODIFY; On the Sales Header Card add the new field in code on AssitEdit IF “File Name” <> ‘’ THEN HYPERLINK(“File Name”); Here ends this Lesson for today. Admin what happend to all my stars? I know I have not been online for a while
Originally posted by David Cox
Admin what happend to all my stars? I know I have not been online for a while
Hahaha, if you not visit the forum once a week you will loose a star[:D]!