How to resolve a text string variable to an object reference
jonwlong
Member Posts: 11
I want to be able to refer to an object, such as a table or a field, using a string parameter. I'm familiar with the RecordRef and FieldRef DataTypes. Below is an overview of my concept.
Assuming that MyRecordRef is a RecordRef object, MyField is a FieldRef object and TableNo is an integer.
My question is: How to resolve a table name to an integer. Or how can I refer to a table or field, using only it's name. Something like this:
Assume strTableName and strFieldName are string variables
Thanks,
Jon
Assuming that MyRecordRef is a RecordRef object, MyField is a FieldRef object and TableNo is an integer.
MyRecordRef.OPEN( intTableNo ); MyFieldRef := MyRecordRef.FIELD( 1 );This allows me to do Get, Validate etc.. using the ref's. Notice that in both cases, an integer is used as a parameter.
My question is: How to resolve a table name to an integer. Or how can I refer to a table or field, using only it's name. Something like this:
Assume strTableName and strFieldName are string variables
MyRecordRef.OPEN( DATABASE::strTableName ); MyFieldRef := MyRecordRef.FIELD( FIELDS::strFieldName );Below is an interesting and valid method of resolving a Table reference to an integer. However, even though "Customer" below resolves to an object it is not derived from a string variable, which is what I am trying to accomplish.
MyRecordRef.OPEN( database::"Customer" );Any discussion on this appreciated.
Thanks,
Jon
Jon Long - ArcherPoint
MCP - Dynamics NAV
MCP - Dynamics NAV
0
Comments
-
Here's an idea that uses the Object table:
PROCEDURE GetTableIDByName(searchName : Text[30]) : Integer VAR Obj : Record 2000000001; BEGIN WITH Obj DO BEGIN SETCURRENTKEY(Type,Name); SETRANGE(Type,Type::Table); SETRANGE(Name,searchName); IF FIND('-') THEN EXIT(ID); END; EXIT(0); END;0 -
I thought about that way but I was really looking for a navision function. I think your object method way will work just fine. Your example is excellent.
Thanks,Jon Long - ArcherPoint
MCP - Dynamics NAV0 -
I am about a year late, but I thought I would post this in case anyone else is searching for a way to convert a field's name to its No. I just found out about the existence of the Field system table.
variable rec_Field is a record variable with subtype Field
rec_Field.SETRANGE(TableNo, intTableNo);
rec_Field.SETRANGE(FieldName, strFieldName);
rec_Field.FIND('-')0 -
darrenc wrote:I am about a year late, but I thought I would post this in case anyone else is searching for a way to convert a field's name to its No.
Wow, thanks! I've been looking for this since ages...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
- 322 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