Running a Loop

david.weeks
Member Posts: 96
Hello All,
I have a button situated within the sales quote subform.
When I press that, I want to automatically insert a new record into a new table I have created called Quote Approval.
There could be many lines within the sales quote subform and I therefore need to run a loop on the sales line table for this order number.
BUT its not working - HELP!
My code is as follows.......Have I approached this totally wrong?
The LSalesLine.FIND is not working as this is looking at the whole sales line table. I want it to just look at the records for that order number.
One other note: I am carrying over the order number from the Sales Header via a function. This value is held in LOrderNo.
IF NOT CONFIRM('Are you sure you want to send this quote for approval?') THEN
EXIT;
LSalesLine.FIND();
REPEAT
IF Type <> 3 THEN BEGIN
END;
IF LSalesLine."Document No." = LOrderNo THEN
//create incremental number for primary key of table
LrecQuoteApproval.RESET;
IF LrecQuoteApproval.FIND('+') THEN BEGIN
LintNextNumber := LrecQuoteApproval.ApprovalReference + 1;
END ELSE BEGIN
LintNextNumber := 1;
END;
//insert into new table QuoteApproval
GQuoteApproval.RESET;
GQuoteApproval.ApprovalReference := LintNextNumber;
GQuoteApproval."Document No._FK" := LSalesLine."Document No.";
GQuoteApproval."Document Type_FK" := LSalesLine."Document Type";
GQuoteApproval."Line No._FK" := LSalesLine."Line No.";
GQuoteApproval.INSERT;
LSalesLine.NEXT;
END;
UNTIL LSalesLine.NEXT = 0;
I have a button situated within the sales quote subform.
When I press that, I want to automatically insert a new record into a new table I have created called Quote Approval.
There could be many lines within the sales quote subform and I therefore need to run a loop on the sales line table for this order number.
BUT its not working - HELP!
My code is as follows.......Have I approached this totally wrong?
The LSalesLine.FIND is not working as this is looking at the whole sales line table. I want it to just look at the records for that order number.
One other note: I am carrying over the order number from the Sales Header via a function. This value is held in LOrderNo.
IF NOT CONFIRM('Are you sure you want to send this quote for approval?') THEN
EXIT;
LSalesLine.FIND();
REPEAT
IF Type <> 3 THEN BEGIN
END;
IF LSalesLine."Document No." = LOrderNo THEN
//create incremental number for primary key of table
LrecQuoteApproval.RESET;
IF LrecQuoteApproval.FIND('+') THEN BEGIN
LintNextNumber := LrecQuoteApproval.ApprovalReference + 1;
END ELSE BEGIN
LintNextNumber := 1;
END;
//insert into new table QuoteApproval
GQuoteApproval.RESET;
GQuoteApproval.ApprovalReference := LintNextNumber;
GQuoteApproval."Document No._FK" := LSalesLine."Document No.";
GQuoteApproval."Document Type_FK" := LSalesLine."Document Type";
GQuoteApproval."Line No._FK" := LSalesLine."Line No.";
GQuoteApproval.INSERT;
LSalesLine.NEXT;
END;
UNTIL LSalesLine.NEXT = 0;
0
Comments
-
Hello All,
I have got it working by changing the line .FIND() to .FIND('-'.
Yes, simple mistake I know....
And I also removed the line LSalesLine.NEXT;
- With this included, I was only getting every other line inserted.
Bye for now0
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