Trigger Problem for Filling a Temporary Table
tompynation
Member Posts: 398
I got a problem for filling up a temporary table inside a subform... This temp table is the sourcetable from this subform
In my mainform i execute the following code:
Form - OnAfterGetRecord()CurrForm.GrondStofSamenStellingSub.FORM.SetProductCode(ID);
CurrForm.GrondStofSamenStellingSub.FORM.FillTempTable;
When i now switch from tabpage, this OnAfterGetRecord gets executed again. This leads to problems cause the FillTempTable get executed again
SetProductCode(ReceptID : Integer)
gv_ReceptID := ReceptID;
FillTempTable()
// Opvullen van Temp table
lv_ReceptItem.RESET;
lv_ReceptItem.SETRANGE(lv_ReceptItem.ReceptID,gv_ReceptID);
lv_ReceptItem.SETFILTER(lv_ReceptItem.ReceptItem,'<>%1','');
IF lv_ReceptItem.FINDFIRST THEN BEGIN
REPEAT
IF lv_Item.GET(lv_ReceptItem.ReceptItem) THEN BEGIN
Rec.Grondstof := lv_Item."No.";
Rec.Type := lv_Item."Item Category Code";
Rec.Omschrijving := lv_Item.Description;
Rec.Hoeveelheid := lv_ReceptItem.Hoeveelheid;
Rec.Percentage := lv_ReceptItem.Percentage;
Rec.INSERT;
COMMIT;
END;
UNTIL lv_ReceptItem.NEXT = 0;
END;
CurrForm.UPDATE(FALSE);
The FilltempTable creates an error cause it will insert duplicate values...
In my mainform i execute the following code:
Form - OnAfterGetRecord()CurrForm.GrondStofSamenStellingSub.FORM.SetProductCode(ID);
CurrForm.GrondStofSamenStellingSub.FORM.FillTempTable;
When i now switch from tabpage, this OnAfterGetRecord gets executed again. This leads to problems cause the FillTempTable get executed again
SetProductCode(ReceptID : Integer)
gv_ReceptID := ReceptID;
FillTempTable()
// Opvullen van Temp table
lv_ReceptItem.RESET;
lv_ReceptItem.SETRANGE(lv_ReceptItem.ReceptID,gv_ReceptID);
lv_ReceptItem.SETFILTER(lv_ReceptItem.ReceptItem,'<>%1','');
IF lv_ReceptItem.FINDFIRST THEN BEGIN
REPEAT
IF lv_Item.GET(lv_ReceptItem.ReceptItem) THEN BEGIN
Rec.Grondstof := lv_Item."No.";
Rec.Type := lv_Item."Item Category Code";
Rec.Omschrijving := lv_Item.Description;
Rec.Hoeveelheid := lv_ReceptItem.Hoeveelheid;
Rec.Percentage := lv_ReceptItem.Percentage;
Rec.INSERT;
COMMIT;
END;
UNTIL lv_ReceptItem.NEXT = 0;
END;
CurrForm.UPDATE(FALSE);
The FilltempTable creates an error cause it will insert duplicate values...
0
Comments
-
Now is there a way that i can fill the temp table only when the subform gets visible?
So not in the onaftergetrecord of the mainform...0 -
Hi
Put your code in the AfterGetCurrRecord
Albert0 -
Might I suggest you could have just edited your previous topic since this is the same issue. Have you tried using my suggestion?
I think it would be rather simple to make a variable to store the current "ProductCode" and set it up so that if that same "ProductCode" is issued again, do nothing.
But for starters, why separate the one function into two? You're calling both at the same place no matter what.Form - OnAfterGetRecord() IF ID <> varProductCode THEN BEGIN varProductCode := ID; CurrForm.GrondStofSamenStellingSub.FORM.FillTempTable(ID); END;FillTempTable(ReceiptID : Integer) lv_ReceptItem.RESET; lv_ReceptItem.SETRANGE(lv_ReceptItem.ReceptID,ReceiptID); lv_ReceptItem.SETFILTER(lv_ReceptItem.ReceptItem,'<>%1',''); IF lv_ReceptItem.FINDSET THEN BEGIN REPEAT IF lv_Item.GET(lv_ReceptItem.ReceptItem) THEN BEGIN Rec.INIT; //<-- Looks like you were missing this... Rec.Grondstof := lv_Item."No."; Rec.Type := lv_Item."Item Category Code"; Rec.Omschrijving := lv_Item.Description; Rec.Hoeveelheid := lv_ReceptItem.Hoeveelheid; Rec.Percentage := lv_ReceptItem.Percentage; Rec.INSERT; END; UNTIL lv_ReceptItem.NEXT = 0; END; CurrForm.UPDATE(FALSE);
You don't need COMMIT since you're writing to a temporary table (aka not the actual database)0 -
thanks the aftergetcurrrecord was what i needed \:D/0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions