validate itemno in sales line,another field will be emptied?
Comments
-
So you can't insert it and you can't modify it after insert?
Are you sure it's getting to that part of your code?
Did you try adding a message line to see if it's executing where you think it should? Message('executing');
Perhaps that section of code only runs for the last line instead of running for each line. Add a message('%1',"line no.");
If its just the last line then your imported=true is in the wrong place0 -
Can you show the file which you are importing?0
-
this is my txt file sampleSale;Invoice;YVO001;TWC-SINV001;EXTDOCNO-001;11/12/2011;COD;30/09/2011;DOMESTIC;AUD;DANNY;19/09/2011;CASH;TRIPLEPACK-SCA;MENLO;PCS;1;20;20;21.4;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;Company A
Sale;Invoice;YVO001;TWC-SINV001;EXTDOCNO-001;11/12/2011;COD;30/09/2011;DOMESTIC;AUD;DANNY;19/09/2011;CASH;CCHINBBQQY;BAYS;BTL;1;30;30;32.1;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;Company A
Sale;Invoice;YVO001;TWC-SINV001;EXTDOCNO-001;11/12/2011;COD;30/09/2011;DOMESTIC;AUD;DANNY;19/09/2011;CASH;CATER-FOOD;MENLO;PCS;1;40;40;42.8;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;Company A
Sale;Credit Memo;BER001;TWC-SCR002;EXTDOCNO-002;12/12/2011;90D;30/09/2011;DOMESTIC;USD;DANNY;19/09/2011;CASH;CCHINBBQQY;BAYS;PCS;1;20;20;21.4;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;Company A
Purchase;Invoice;ANG001;TWC-PINV001;TEXTCAPSLOCK;26/12/2011;COD;30/09/2011;FOREIGN;AUD;BELINDA;20/09/2011;VISA;CATER-FOOD;MENLO;PCS;1;30;30;32.1;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;Company A
Sale;Invoice;ASA001;TWC-SINV002;EXTDOCNO-002;23/12/2011;COD;30/09/2011;DOMESTIC;USD;BELINDA;19/09/2011;CASH;BULBHOLDER;BAYS;PCS;1;20;20;21.4;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;TEXTCAPSLOCK;Company A0 -
Savatage wrote:So you can't insert it and you can't modify it after insert?
Are you sure it's getting to that part of your code?
Did you try adding a message line to see if it's executing where you think it should? Message('executing');
Perhaps that section of code only runs for the last line instead of running for each line.
Add a message('%1 %2 %3',"Document Type","Document No.","line no.");
If its just the last line then your imported=true is in the wrong place0 -
kapamarou wrote:So strange... Could your field be a flowfield? :-k
i use boolean as normal type0 -
Savatage wrote:So you can't insert it and you can't modify it after insert?
Are you sure it's getting to that part of your code?
Did you try adding a message line to see if it's executing where you think it should? Message('executing');
Perhaps that section of code only runs for the last line instead of running for each line. Add a message('%1',"line no.");
If its just the last line then your imported=true is in the wrong place
after sales line inserted... i tried previously catch using message
and it's all correct.... imported is true, and description is Test
but after that... the result is wrong0 -
Try this
GLSetup.GET; SFile.TEXTMODE(TRUE); SFile.WRITEMODE(FALSE); SFile.OPEN('D:\Data\Test.txt'); REPEAT SFile.READ(vString); //Transaction Type PosCode:=STRPOS(vString,';'); vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); IF vStringTransaction = 'Sale' THEN BEGIN //********* SALES HEADER ************ //SH Document Type PosCode:=STRPOS(vString,';'); IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Order' THEN SH."Document Type" := SH."Document Type"::Order; IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Invoice' THEN SH."Document Type" := SH."Document Type"::Invoice; IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Return Order' THEN SH."Document Type" := SH."Document Type"::"Return Order"; IF FORMAT(COPYSTR(vString,1,PosCode-1)) = 'Credit Memo' THEN SH."Document Type" := SH."Document Type"::"Credit Memo"; vString:=DELSTR(vString,1,PosCode); DocType := SH."Document Type"; //SH No. & SH Sell-to Customer No PosCode:=STRPOS(vString,';'); SH."Sell-to Customer No." := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); PosCode:=STRPOS(vString,';'); SH."No." := FORMAT(COPYSTR(vString,1,PosCode-1)); IF (SH."Document Type" <> TempDocType) AND (SH."No." <> TempDocNo) THEN BEGIN vString:=DELSTR(vString,1,PosCode); SH.VALIDATE(SH."No."); SH.InitRecord; SH.SetHideValidationDialog(TRUE); DocNo := SH."No."; //External Doc No. PosCode:=STRPOS(vString,';'); SH."External Document No." := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); //Posting Date PosCode:=STRPOS(vString,';'); PostingDateText := FORMAT(COPYSTR(vString,1,PosCode-1)); SH."Posting Date" := ConvertPostingDate(PostingDateText); vString:=DELSTR(vString,1,PosCode); //Payment Terms Code PosCode:=STRPOS(vString,';'); SH."Payment Terms Code" := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); //Due Date PosCode:=STRPOS(vString,';'); SalesDueDateText := FORMAT(COPYSTR(vString,1,PosCode-1)); SH."Due Date" := ConvertSalesDueDate(SalesDueDateText); vString:=DELSTR(vString,1,PosCode); //Vendor / Customer Posting Group PosCode:=STRPOS(vString,';'); SH."Customer Posting Group" := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); //Currency Code PosCode:=STRPOS(vString,';'); SH."Currency Code" := FORMAT(COPYSTR(vString,1,PosCode-1)); SH.VALIDATE(SH."Currency Code"); vString:=DELSTR(vString,1,PosCode); //Purchaser / Salesperson Code PosCode:=STRPOS(vString,';'); SH."Salesperson Code" := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); // Document Date PosCode:=STRPOS(vString,';'); SalesDocumentDateText := FORMAT(COPYSTR(vString,1,PosCode-1)); SH."Document Date" := ConvertSalesDocumentDate(SalesDocumentDateText); vString:=DELSTR(vString,1,PosCode); //Payment Method PosCode:=STRPOS(vString,';'); SH."Payment Method Code" := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); SH.Imported := TRUE; SH.INSERT(TRUE); END ELSE BEGIN vString:=DELSTR(vString,1,PosCode); DocNo := SH."No."; //External Doc No. PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); //Posting Date PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); //Payment Terms Code PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); //Due Date PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); //Vendor / Customer Posting Group PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); //Currency Code PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); //Purchaser / Salesperson Code PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); // Document Date PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); //Payment Method PosCode:=STRPOS(vString,';'); vString:=DELSTR(vString,1,PosCode); END; TempDocType := SH."Document Type"; TempDocNo := SH."No."; //*********** SALES LINE ************ SL.RESET; SL.SETRANGE(SL."Document Type",DocType); SL.SETRANGE(SL."Document No.",DocNo); IF SL.FIND('+') THEN LineNo := SL."Line No." + 10000 ELSE LineNo := 10000; SL.RESET; SL.INIT; SL."Document Type" := DocType; SL."Document No." := DocNo; SL."Line No." := LineNo; SL.VALIDATE(Type,SL.Type::Item); //Item No. PosCode:=STRPOS(vString,';'); SL.VALIDATE(SL."No.",FORMAT(COPYSTR(vString,1,PosCode-1))); vString:=DELSTR(vString,1,PosCode); SL.Description := 'Test'; SL.Imported := TRUE; SL.INSERT(TRUE); END; UNTIL SFile.POS = SFile.LEN; MESSAGE('Import Done');
Microsoft Certified IT Professional for Microsoft Dynamics NAV
Just a happy frood who knows where his towel is0 -
Or this:
GLSetup.GET; SFile.TEXTMODE(TRUE); SFile.WRITEMODE(FALSE); SFile.OPEN('D:\Data\Test.txt'); REPEAT SFile.READ(vString); //Transaction Type PosCode:=STRPOS(vString,';'); vStringTransaction := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); IF vStringTransaction = 'Sale' THEN BEGIN //********* SALES HEADER ************ //SH Document Type PosCode:=STRPOS(vString,';'); CASE FORMAT(COPYSTR(vString,1,PosCode-1)) OF 'Order' : SH."Document Type" := SH."Document Type"::Order; 'Invoice' : SH."Document Type" := SH."Document Type"::Invoice; 'Return order' : SH."Document Type" := SH."Document Type"::"Return order"; 'Credit memo' : SH."Document Type" := SH."Document Type"::"Credit memo"; END; vString:=DELSTR(vString,1,PosCode); DocType := SH."Document Type"; //SH No. & SH Sell-to Customer No PosCode:=STRPOS(vString,';'); CustomerNo := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); PosCode:=STRPOS(vString,';'); DocNo := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); DoNewHeader := (SH."Document Type" <> DocType) OR (SH."No." <> DocNo); IF DoNewHeader THEN BEGIN SH.InitRecord; SH.SetHideValidationDialog(TRUE); SH.VALIDATE("No.", DocNo); SH.VALIDATE("Sell-to Customer No.", CustomerNo); END; //External Doc No. PosCode:=STRPOS(vString,';'); SH."External Document No." := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); //Posting Date PosCode:=STRPOS(vString,';'); PostingDateText := FORMAT(COPYSTR(vString,1,PosCode-1)); SH."Posting Date" := ConvertPostingDate(PostingDateText); vString:=DELSTR(vString,1,PosCode); //Payment Terms Code PosCode:=STRPOS(vString,';'); SH."Payment Terms Code" := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); //Due Date PosCode:=STRPOS(vString,';'); SalesDueDateText := FORMAT(COPYSTR(vString,1,PosCode-1)); SH."Due Date" := ConvertSalesDueDate(SalesDueDateText); vString:=DELSTR(vString,1,PosCode); //Vendor / Customer Posting Group PosCode:=STRPOS(vString,';'); SH."Customer Posting Group" := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); //Currency Code PosCode:=STRPOS(vString,';'); IF DoNewHeader THEN SH.VALIDATE("Currency Code", FORMAT(COPYSTR(vString,1,PosCode-1))); vString:=DELSTR(vString,1,PosCode); //Purchaser / Salesperson Code PosCode:=STRPOS(vString,';'); SH."Salesperson Code" := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); // Document Date PosCode:=STRPOS(vString,';'); SalesDocumentDateText := FORMAT(COPYSTR(vString,1,PosCode-1)); SH."Document Date" := ConvertSalesDocumentDate(SalesDocumentDateText); vString:=DELSTR(vString,1,PosCode); //Payment Method PosCode:=STRPOS(vString,';'); SH."Payment Method Code" := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); SH.Imported := TRUE; IF DoNewHeader THEN SH.INSERT(TRUE); //*********** SALES LINE ************ SL.RESET; SL.SETRANGE("Document Type",DocType); SL.SETRANGE("Document No.",DocNo); IF SL.FIND('+') THEN LineNo := SL."Line No." + 10000 ELSE LineNo := 10000; SL.RESET; SL."Document Type" := DocType; SL."Document No." := DocNo; SL."Line No." := LineNo; SL.Type := SL.Type::Item; //Item No. PosCode:=STRPOS(vString,';'); SL.VALIDATE("No.",FORMAT(COPYSTR(vString,1,PosCode-1))); vString:=DELSTR(vString,1,PosCode); SL.Description := 'Test'; SL.Imported := TRUE; SL.INSERT(TRUE); END; UNTIL SFile.POS = SFile.LEN; MESSAGE('Import Done');
0 -
Hi Dans and Bernard
now it's work
thanks for your helps
can anyone share what happened previously?0 -
When you validate the Customer No. on the header, Nav recreates / refresh the Sales Line. That is why the previously inserted Sales Lines Imported Field is set back to default (FALSE).Microsoft Certified IT Professional for Microsoft Dynamics NAV
Just a happy frood who knows where his towel is0 -
dans wrote:When you validate the Customer No. on the header, Nav recreates / refresh the Sales Line. That is why the previously inserted Sales Lines Imported Field is set back to default (FALSE).
another problem if we import multiple documents
previously we tried for doc TWC-SINV0001
but if we using this one... failed
i changed now my data hava 2 documents : TWC-SINV0001 and TWC-SINV0002
it was said sales header document type : invoice and no TWC-SINV0002 does not existSale;Invoice;CUST001;TWC-SINV001;EXTDOCNO-001;11/12/2011;COD;30/09/2011;TWCI;AUD;DENNIES;19/09/2011;CASH;TRIPLEPACK-SCA;BLUE;PCS;3;100;10;TEXTCAPSLOCK1-1;TEXTCAPSLOCK1-2;TEXTCAPSLOCK1-3;TEXTCAPSLOCK1-4;TEXTCAPSLOCK1-5;Company A Pte. Ltd.
Sale;Invoice;CUST001;TWC-SINV002;EXTDOCNO-011;11/12/2011;COD;30/09/2011;TWCI;AUD;DANNY;19/09/2011;CASH;CCHINBBQQY;BOXSAS;BTL;1;200;20;TEXTCAPSLOCK2-1;;TEXTCAPSLOCK2-3;TEXTCAPSLOCK2-4;TEXTCAPSLOCK2-5;Company A Pte. Ltd.0 -
Try this:
IF (SH."Document Type" <> TempDocType) AND OR (SH."No." <> TempDocNo) THEN0 -
BernardJ wrote:Try this:
IF (SH."Document Type" <> TempDocType) AND OR (SH."No." <> TempDocNo) THEN
anyway i need these 2 conditions
i dont think i can use OR0 -
dans wrote:When you validate the Customer No. on the header, Nav recreates / refresh the Sales Line. That is why the previously inserted Sales Lines Imported Field is set back to default (FALSE).
then the sales header only get customer code... and not validated
i think this one is still wrong0 -
you just need to make sure you dont validate if the header is already existed.Microsoft Certified IT Professional for Microsoft Dynamics NAV
Just a happy frood who knows where his towel is0 -
hi dan
i think it works
i put a code like this
thanks man ! =D>. . . . PosCode:=STRPOS(vString,';'); SH."No." := FORMAT(COPYSTR(vString,1,PosCode-1)); vString:=DELSTR(vString,1,PosCode); SH.VALIDATE(SH."No."); SH.InitRecord; SH.SetHideValidationDialog(TRUE); DocNo := SH."No."; CheckSalesHeader.RESET; CheckSalesHeader.SETRANGE(CheckSalesHeader."Document Type",SH."Document Type"); CheckSalesHeader.SETRANGE(CheckSalesHeader."No.",SH."No."); IF NOT CheckSalesHeader.FIND('-') THEN SH.VALIDATE(SH."Sell-to Customer No.") ELSE SH.GET(SH."Document Type",SH."No."); . . . .
0 -
glad I could help.
actually there is a few things that you could do to improve the coding, such as the variable naming, use GET instead of SETRANGE, etc.
IF NOT CheckSalesHeader.GET(SH."Document Type",SH."No.") THEN
SH.VALIDATE(SH."Sell-to Customer No.")
ELSE
SH.GET(SH."Document Type",SH."No.");
I will let you decide it for yourself though.Microsoft Certified IT Professional for Microsoft Dynamics NAV
Just a happy frood who knows where his towel is0 -
dans wrote:glad I could help.
actually there is a few things that you could do to improve the coding, such as the variable naming, use GET instead of SETRANGE, etc.
IF NOT CheckSalesHeader.GET(SH."Document Type",SH."No.") THEN
SH.VALIDATE(SH."Sell-to Customer No.")
ELSE
SH.GET(SH."Document Type",SH."No.");
I will let you decide it for yourself though.
thanks a lot Dan0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions