FINDSET and Rename

JDVyska
Member Posts: 179
I have a client project I'm working on where they need a custom table merged to multicompany, but each company has records in it. So, I'm simply going to add an offset # per company, say 100 per each company.
So, the example data is simple, ID is the only PK field, an integer:
The result should be roughly:
I was thinking I'd be slick and use FINDSET(TRUE,TRUE), since that allows modification, even on the key you're using.
Turns out, FINDSET can't quite be used that way. Company B's 1 becomes 101, then it's at the end of the dataset and stops.
In my case, it's easy to iterate like:
Just thought I'd share this, since I misunderstood FINDSET's TRUE,TRUE combination. If I can, someone else will also eventually and come here.
Edit: Yes, I know most of the time you'd be better off copying to a temp buffer, renaming, copying back, or even insert/deletes, but in the actual details of my situation, not the simplicity of the above example, I have a host of tablerelations to this master table, so I want NAV to cascade the RENAME for me.
So, the example data is simple, ID is the only PK field, an integer:
Company A: ID | Some text 1 | Text 2 | Text 3 | Text Company B: ID | Some text 1 | Text 2 | Text 3 | Text
The result should be roughly:
Company A: ID | Some text 1 | Text 2 | Text 3 | Text 101 | Text 102 | Text 103 | Text
I was thinking I'd be slick and use FINDSET(TRUE,TRUE), since that allows modification, even on the key you're using.
Turns out, FINDSET can't quite be used that way. Company B's 1 becomes 101, then it's at the end of the dataset and stops.
In my case, it's easy to iterate like:
Offset := 100; // in real code, I'd bump this up per company IF Custom.FINDFIRST THEN REPEAT Custom.RENAME(Custom.ID+Offset); IF Custom.FINDFIRST THEN; UNTIL Custom.ID >= Offset;
Just thought I'd share this, since I misunderstood FINDSET's TRUE,TRUE combination. If I can, someone else will also eventually and come here.

Edit: Yes, I know most of the time you'd be better off copying to a temp buffer, renaming, copying back, or even insert/deletes, but in the actual details of my situation, not the simplicity of the above example, I have a host of tablerelations to this master table, so I want NAV to cascade the RENAME for me.
JEREMY VYSKA
CEO, Spare Brained Ideas, Göteborg, Sweden
New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
CEO, Spare Brained Ideas, Göteborg, Sweden
New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"
1
Answers
-
basically, you were doing a so called "next from hell":
ideally, your loop should look like thisOffset := 100; // in real code, I'd bump this up per company IF Custom.FINDSET(TRUE,TRUE) THEN REPEAT // Aaargh!!!use findset, not findfirst with loops!!! Custom2 := Custom; Custom2.RENAME(Custom.ID+Offset); UNTIL Custom.ID >= Offset;
the parameters of the findset function just changes some parameters of the query sent to sql (isolation level for locking purposes), it does not allow you to do avoid a next from hell issue.1 -
what about filtering one record set, repeat until, and in that loop, get another instance of the record and rename that?kind of fell into this...0
-
Belias wrote:basically, you were doing a so called "next from hell":Belias wrote:the parameters of the findset function just changes some parameters of the query sent to sql (isolation level for locking purposes), it does not allow you to do avoid a next from hell issue.
Yuppers. It's a very crazy project I'm working on, so there's no avoiding ugly 100%. I figured if I could fall into the "next from hell" trap thinking FINDSET would magically save me, it was bound to catch someone else.JEREMY VYSKA
CEO, Spare Brained Ideas, Göteborg, Sweden
New (April 2021) Getting Started with Microsoft Dynamics 365 Business Central Book Available: "Your First 20 Hours with Business Central"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
- 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