Filter on specific record with RecordRef or FieldRef

wester
Member Posts: 33
Hi there.
I wish to filter my recordset to a specific record, but it seems to give me troubles. I've tried 2 different approaches, but each of them just ignores my way of setting a filter, and returns the value of the very first record in the table.
The following code is run within a REPEAT-LOOP, which changes the: "ChosenField" variable to a different field in the record after each LOOP.
*** SEE CODE IN NEXT POSTING BELOW THIS...
In example 1 I've used the SETPOSITION method, and in example 2 I've used the SETRANGE-method of the FieldRef function.
None of them filters the recordset.
Can anyone see what I'm doing wrong?
Thank you for reading this.
/Wester
I wish to filter my recordset to a specific record, but it seems to give me troubles. I've tried 2 different approaches, but each of them just ignores my way of setting a filter, and returns the value of the very first record in the table.
The following code is run within a REPEAT-LOOP, which changes the: "ChosenField" variable to a different field in the record after each LOOP.
*** SEE CODE IN NEXT POSTING BELOW THIS...
In example 1 I've used the SETPOSITION method, and in example 2 I've used the SETRANGE-method of the FieldRef function.
None of them filters the recordset.
Can anyone see what I'm doing wrong?
Thank you for reading this.
/Wester
0
Comments
-
The code looks like this:
NaviTable := 18;
CurrPrimaryKeyField := 'No.';
WantedRec := '502200';
// Example 1:
RecRef.OPEN(NaviTable);
RecRef.SETPOSITION('"' + CurrPrimaryKeyField + '"=FILTER(' + WantedRec + ')');
FldRef := RecRef.FIELD(ChosenField);
IF RecRef.FIND('-') THEN BEGIN
MESSAGE(FORMAT(FldRef.VALUE));
RecRef.CLOSE;
END;
// Example 2:
RecRef.OPEN(NaviTable);
FldRef := RecRef.FIELD(ChosenField);
FldRef.SETRANGE(CurrPrimaryKeyField, WantedRec);
IF RecRef.FIND('-') THEN BEGIN
MESSAGE(FORMAT(FldRef.VALUE));
RecRef.CLOSE;
END;0 -
Example 1: SETPOSITION does not set any filters, it simply places values in the primary key field(s) of the record. After SETPOSITION, use FIND('=') instead of FIND('-')...
Example 2: The syntax of SETRANGE for FldRefs is SETRANGE(FromValue,ThruValue), where you can omit ThruValue for a single value filter. So, I think you meant to code it FldRef.SETRANGE(WantedRec);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