Endless Loop
 
            
                
                    nmonty                
                
                    Member Posts: 20                
            
                        
            
                    Hi All,
I have written a code so as when the user does some entry in the Item Journal & by clicking a button he gets -ve adjmt entry same as for the entry he has done.
My problem is that my code is getting into the loop & is telling me to expand the databse.
My code is as follows:
RecItemJnlLine2.RESET;
RecItemJnlLine2.SETRANGE("Journal Template Name",JnlTemplateName);
RecItemJnlLine2.SETRANGE("Journal Batch Name",JnlBatchName);
IF RecItemJnlLine2.FINDSET THEN
REPEAT
NewLineNo := NewLineNo + 10000;
CustAmount := RecItemJnlLine2.Amount;
RecItemJnlLine3."Journal Template Name" := JnlTemplateName;
RecItemJnlLine3."Journal Batch Name" := JnlBatchName;
RecItemJnlLine3."Posting No. Series" := GetPostNoSeriesFromIJBTable(JnlTemplateName,JnlBatchName);
RecItemJnlLine3."Posting Date" := RecItemJnlLine2."Posting Date";
RecItemJnlLine3."Line No." := NewLineNo;
RecItemJnlLine3.VALIDATE("Item No.",RecItemJnlLine2."Item No.");
RecItemJnlLine3."Entry Type" := RecItemJnlLine2."Entry Type" :: "Negative Adjmt.";
RecItemJnlLine3."Document Type" := RecItemJnlLine2."Document Type";
RecItemJnlLine3."Document No." := RecItemJnlLine2."Document No.";
RecItemJnlLine3.Quantity := RecItemJnlLine2.Quantity;
RecItemJnlLine3.Amount := CustAmount;
RecItemJnlLine3."Source Code" := RecItemJnlLine2."Source Code";
RecItemJnlLine3.VALIDATE(RecItemJnlLine3.Amount);
RecItemJnlLine3."Posting Date" := RecItemJnlLine2."Posting Date";
RecItemJnlLine3.VALIDATE("Document Date",RecItemJnlLine2."Document Date");
RecItemJnlLine3.INSERT;
UNTIL RecItemJnlLine2.NEXT = 0;
Thnx in advance.
                I have written a code so as when the user does some entry in the Item Journal & by clicking a button he gets -ve adjmt entry same as for the entry he has done.
My problem is that my code is getting into the loop & is telling me to expand the databse.
My code is as follows:
RecItemJnlLine2.RESET;
RecItemJnlLine2.SETRANGE("Journal Template Name",JnlTemplateName);
RecItemJnlLine2.SETRANGE("Journal Batch Name",JnlBatchName);
IF RecItemJnlLine2.FINDSET THEN
REPEAT
NewLineNo := NewLineNo + 10000;
CustAmount := RecItemJnlLine2.Amount;
RecItemJnlLine3."Journal Template Name" := JnlTemplateName;
RecItemJnlLine3."Journal Batch Name" := JnlBatchName;
RecItemJnlLine3."Posting No. Series" := GetPostNoSeriesFromIJBTable(JnlTemplateName,JnlBatchName);
RecItemJnlLine3."Posting Date" := RecItemJnlLine2."Posting Date";
RecItemJnlLine3."Line No." := NewLineNo;
RecItemJnlLine3.VALIDATE("Item No.",RecItemJnlLine2."Item No.");
RecItemJnlLine3."Entry Type" := RecItemJnlLine2."Entry Type" :: "Negative Adjmt.";
RecItemJnlLine3."Document Type" := RecItemJnlLine2."Document Type";
RecItemJnlLine3."Document No." := RecItemJnlLine2."Document No.";
RecItemJnlLine3.Quantity := RecItemJnlLine2.Quantity;
RecItemJnlLine3.Amount := CustAmount;
RecItemJnlLine3."Source Code" := RecItemJnlLine2."Source Code";
RecItemJnlLine3.VALIDATE(RecItemJnlLine3.Amount);
RecItemJnlLine3."Posting Date" := RecItemJnlLine2."Posting Date";
RecItemJnlLine3.VALIDATE("Document Date",RecItemJnlLine2."Document Date");
RecItemJnlLine3.INSERT;
UNTIL RecItemJnlLine2.NEXT = 0;
Thnx in advance.
0                
            Answers
- 
            In which trigger did you put this code? If you put it in either one of the following OnValidate-Trigger, you could have an endless loop because of the VALIDATE(...) calls in your code:
 "Item No."
 Amount
 "Document Date0
- 
            I have written a function in Item Jnl Mgmt. Codeunit & passed Item Jnl Line as a parameter there.0
- 
            I think that RecItemJnlLine2 and RecItemJnlLine3 are the same record so:
 Everytime you insert a line in RecItemJnlLine3 that line becomes the next line for RecItemJnlLine2 and so on and so forth. What you could do is the following to skip the new lines in RecItemJnlLine2:
 try it and let us know...
 RecItemJnlLine2.RESET;
 RecItemJnlLine2.SETRANGE("Journal Template Name",JnlTemplateName);
 RecItemJnlLine2.SETRANGE("Journal Batch Name",JnlBatchName);IF RecItemJnlLine2.FINDLAST THEN RecItemJnlLine2.SETRANGE("Line No.",0,RecItemJnlLine2."Line No");IF RecItemJnlLine2.FINDSET THEN
 REPEAT
 NewLineNo := NewLineNo + 10000;
 CustAmount := RecItemJnlLine2.Amount;
 RecItemJnlLine3."Journal Template Name" := JnlTemplateName;
 RecItemJnlLine3."Journal Batch Name" := JnlBatchName;
 RecItemJnlLine3."Posting No. Series" := GetPostNoSeriesFromIJBTable(JnlTemplateName,JnlBatchName);
 RecItemJnlLine3."Posting Date" := RecItemJnlLine2."Posting Date";
 RecItemJnlLine3."Line No." := NewLineNo;
 RecItemJnlLine3.VALIDATE("Item No.",RecItemJnlLine2."Item No.");
 RecItemJnlLine3."Entry Type" := RecItemJnlLine2."Entry Type" :: "Negative Adjmt.";
 RecItemJnlLine3."Document Type" := RecItemJnlLine2."Document Type";
 RecItemJnlLine3."Document No." := RecItemJnlLine2."Document No.";
 RecItemJnlLine3.Quantity := RecItemJnlLine2.Quantity;
 RecItemJnlLine3.Amount := CustAmount;
 RecItemJnlLine3."Source Code" := RecItemJnlLine2."Source Code";
 RecItemJnlLine3.VALIDATE(RecItemJnlLine3.Amount);
 RecItemJnlLine3."Posting Date" := RecItemJnlLine2."Posting Date";
 RecItemJnlLine3.VALIDATE("Document Date",RecItemJnlLine2."Document Date");
 RecItemJnlLine3.INSERT;
 UNTIL RecItemJnlLine2.NEXT = 0;0
- 
            Thnx a lot.
 It worked.0
- 
            You're welcome... 0 0
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
- 323 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

