Tables Collection?

mstallmann
Member Posts: 138
Is there a way to loop through all of the tables in the database? I am trying to search and replace on all of the tables/fields in the database. I saw a post where someone looped through:
Foreach Table do
- Foreach Record (using recref) do
- Foreach Field (using virtual Fields) do
- check recref.fieldref.value for string
But this is VB code...navision doesn't have a for each...does it?????
Confused,
Mike
Foreach Table do
- Foreach Record (using recref) do
- Foreach Field (using virtual Fields) do
- check recref.fieldref.value for string
But this is VB code...navision doesn't have a for each...does it?????
Confused,
Mike
0
Comments
-
Hope this helps,
VAR v_AllObjects@1000000000 : Record 2000000038; v_RecRef@1000000001 : RecordRef; v_FldRef@1000000002 : FieldRef; v_I@1000000003 : Integer; v_Modify@1000000004 : Boolean BEGIN WITH v_AllObjects DO BEGIN SETRANGE("Object type", "Object type"::Table); SETFILTER("Object ID", '<%1', 2000000001); // Non-system tables IF FIND('-') THEN REPEAT v_RecRef.OPEN("Object ID"); v_Modify := FALSE; FOR v_I := 1 TO v_RecRef.FIELDCOUNT DO BEGIN v_FldRef := v_RecRef.FIELDINDEX(v_I); // +++ << Your code here >> IF <Your conditions> THEN BEGIN v_FldRef.VALIDATE(<Your value>); v_Modify := TRUE; END; // --- END; // +++ << Your code here >> IF v_Modify THEN v_RecRef.MODIFY(<TRUE/FALSE>) // --- v_RecRef.CLOSE; UNTIL NEXT = 0; END; END;
0 -
Thank you for your help...You're a stud...
Just needed to add one more loop...thought I'd put it up there for future users looking for same solution...
VAR
v_AllObjects@1000000000 : Record 2000000038;
v_RecRef@1000000001 : RecordRef;
v_FldRef@1000000002 : FieldRef;
v_I@1000000003 : Integer;
v_Modify@1000000004 : Boolean
BEGIN
WITH v_AllObjects DO BEGIN
SETRANGE("Object type", "Object type"::Table);
SETFILTER("Object ID", '<%1', 2000000001); // Non-system tables
IF FIND('-') THEN
REPEAT
v_RecRef.OPEN("Object ID");
v_Modify := FALSE;
*Add* IF v_RecRef.FIND('-') THEN BEGIN
*Add* REPEAT
FOR v_I := 1 TO v_RecRef.FIELDCOUNT DO BEGIN
v_FldRef := v_RecRef.FIELDINDEX(v_I);
// +++ << Your code here >>
IF <Your conditions> THEN BEGIN
v_FldRef.VALIDATE(<Your value>);
v_Modify := TRUE;
END;
*Add* UNTIL RecRef.NEXT=0;
*Add* END;
// ---
END;
// +++ << Your code here >>
IF v_Modify THEN v_RecRef.MODIFY(<TRUE/FALSE>)
// ---
v_RecRef.CLOSE;
UNTIL NEXT = 0;
END;
END;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