Cannot Insert Second Record into Temp Table

daniel_mitrea_1995
Member Posts: 26
Using a report, I have a dataItem based on Ax Slave table. On After Get Record trigger I want to check if there is already inserted the combination between customer, caseID and InsuranceCompanyName and if it's then I just increment one field. I'm using the same table Ax Slave but is a temp table
The problem is that I cannot insert more than one record in the temp table.
I have the following code:
AX Slave - OnAfterGetRecord()
TempAXSlave.SETRANGE(AccountNumber,"AX Slave".AccountNumber);
TempAXSlave.SETRANGE(CaseID,"AX Slave".CaseID);
TempAXSlave.SETRANGE(InsuranceCompanyName,"AX Slave".InsuranceCompanyName);
IF TempAXSlave.FINDFIRST THEN BEGIN
TempAXSlave.MaxResults += 1;
TempAXSlave.MODIFY;
END ELSE BEGIN
TempAXSlave.INIT;
//SlaveID += 1;
TempAXSlave.SlaveID += 1;
TempAXSlave.AccountNumber := "AX Slave".AccountNumber;
TempAXSlave.CaseID := "AX Slave".CaseID;
TempAXSlave.InsuranceCompanyName := "AX Slave".InsuranceCompanyName;
TempAXSlave.INSERT;
END;
on the AX Slave - OnPostDataItem() I want to generate an excel file based on the temp table. But when I do TempAXSlave.FINDSET I see there is only one record in that table.
Can you please help me with this problem ?
The problem is that I cannot insert more than one record in the temp table.
I have the following code:
AX Slave - OnAfterGetRecord()
TempAXSlave.SETRANGE(AccountNumber,"AX Slave".AccountNumber);
TempAXSlave.SETRANGE(CaseID,"AX Slave".CaseID);
TempAXSlave.SETRANGE(InsuranceCompanyName,"AX Slave".InsuranceCompanyName);
IF TempAXSlave.FINDFIRST THEN BEGIN
TempAXSlave.MaxResults += 1;
TempAXSlave.MODIFY;
END ELSE BEGIN
TempAXSlave.INIT;
//SlaveID += 1;
TempAXSlave.SlaveID += 1;
TempAXSlave.AccountNumber := "AX Slave".AccountNumber;
TempAXSlave.CaseID := "AX Slave".CaseID;
TempAXSlave.InsuranceCompanyName := "AX Slave".InsuranceCompanyName;
TempAXSlave.INSERT;
END;
on the AX Slave - OnPostDataItem() I want to generate an excel file based on the temp table. But when I do TempAXSlave.FINDSET I see there is only one record in that table.
Can you please help me with this problem ?
0
Best Answer
-
I would do something like this:
AX Slave - OnAfterGetRecord() // Save the last entry ID before TempAXSlave.RESET; IF TempAXSlave.FINDLAST THEN EntryID := TempAXSlave.SlaveID + 1 ELSE EntryID := 1; TempAXSlave.SETRANGE(AccountNumber,"AX Slave".AccountNumber); TempAXSlave.SETRANGE(CaseID,"AX Slave".CaseID); TempAXSlave.SETRANGE(InsuranceCompanyName,"AX Slave".InsuranceCompanyName); IF TempAXSlave.FINDFIRST THEN BEGIN TempAXSlave.MaxResults += 1; TempAXSlave.MODIFY; END ELSE BEGIN TempAXSlave.INIT; //SlaveID += 1; TempAXSlave.SlaveID := EntryID; // Put here the entry ID TempAXSlave.AccountNumber := "AX Slave".AccountNumber; TempAXSlave.CaseID := "AX Slave".CaseID; TempAXSlave.InsuranceCompanyName := "AX Slave".InsuranceCompanyName; TempAXSlave.INSERT; END;
I will search the last ID before everything so I am sure that if I do an insert if have the last ID and I won't overwrite the record or worse, get an error.
But the I think that real problem is that, when you do the FINDSET in the AX Slave - OnPostDataItem() your are doing a RESET before right? Because I will keep your SETRANGE filters and for that reason on the FINDSET it will find only one record. Probably the last of your list.5
Answers
-
I would do something like this:
AX Slave - OnAfterGetRecord() // Save the last entry ID before TempAXSlave.RESET; IF TempAXSlave.FINDLAST THEN EntryID := TempAXSlave.SlaveID + 1 ELSE EntryID := 1; TempAXSlave.SETRANGE(AccountNumber,"AX Slave".AccountNumber); TempAXSlave.SETRANGE(CaseID,"AX Slave".CaseID); TempAXSlave.SETRANGE(InsuranceCompanyName,"AX Slave".InsuranceCompanyName); IF TempAXSlave.FINDFIRST THEN BEGIN TempAXSlave.MaxResults += 1; TempAXSlave.MODIFY; END ELSE BEGIN TempAXSlave.INIT; //SlaveID += 1; TempAXSlave.SlaveID := EntryID; // Put here the entry ID TempAXSlave.AccountNumber := "AX Slave".AccountNumber; TempAXSlave.CaseID := "AX Slave".CaseID; TempAXSlave.InsuranceCompanyName := "AX Slave".InsuranceCompanyName; TempAXSlave.INSERT; END;
I will search the last ID before everything so I am sure that if I do an insert if have the last ID and I won't overwrite the record or worse, get an error.
But the I think that real problem is that, when you do the FINDSET in the AX Slave - OnPostDataItem() your are doing a RESET before right? Because I will keep your SETRANGE filters and for that reason on the FINDSET it will find only one record. Probably the last of your list.5 -
Removing the filters did the trick. Caught up in the problem and forget the details
Thank you. I really appreciate0
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