Hello forum! I’m a Navision developer newbie, so bear with me. Our Sales Cr.Memo Line table has 5 keys defined. The first key is “Document No.”,“Line No.” and the last is “Sell-to Customer No.”,“Shortcut Dimension 1 Code”,“Shortcut Dimension 2 Code”. I have the global variable recCrMemo defined for a report with a datatype of Record and subtype of Sales Cr.Memo Line. In code I’m doing the following (for proof of concept): recCrMemo.SETCURRENTKEY(“Sell-to Customer No.”,“Shortcut Dimension 1 Code”,“Shortcut Dimension 2 Code”); recCrMemo.“Sell-to Customer No.” := ‘1’; recCrMemo.“Shortcut Dimension 1 Code” := ‘SPORTS’; recCrMemo.“Shortcut Dimension 2 Code” := ‘01FBPPRF’; recCrMemo.FIND; Instead of finding the first record containing those values, the report throws an error. It is appending the first key fields to the end of the current key fields, and since I’m not populating those fields it can’t find the relevant record. Am I completely missing something here? Any input would be helpful. Thanks in advance! --rbentley
There are two important aspects here: 1) The primary key fields (the first key defined for the table) are always appended to the other keys’ fields in order to make the sorting order unambiguous. You already mentioned this. 2) Calling FIND without parameters searches for a record that matches the values stored in the current key’s fields. This includes the primary key fields. It throws an error if it doesn’t find a match. The behaviour you are observing is therefore entirely correct and in accordance with Navision’s rules, although it might not be what you expected [;)] If you want to search for a record that meets the specified criteria, you should instead use SETRANGE or SETFILTER on the relevant fields and then call FIND(’-’) or FIND(’+’). This will give you the first or last record to meet the filter criteria.
call FIND(’-’) or FIND(’+’).
Exactly. So in your case it should be
recCrMemo.SETCURRENTKEY("Sell-to Customer No.","Shortcut Dimension 1 Code","Shortcut Dimension 2 Code"); recCrMemo.SETRANGE("Sell-to Customer No.", '1'); recCrMemo.SETRANGE("Shortcut Dimension 1 Code", 'SPORTS'); recCrMemo.SETRANGE("Shortcut Dimension 2 Code", '01FBPPRF'); recCrMemo.FIND('-'); Best regards, Jörg
Aha! I missed the fact that the primary key is appended to the other keys in the case of SETCURRENTKEY. Silly developer, documentation is for kids! It looks like the SETFILTER is going to work. Thanks for the input!
Jörg, I didn’t know that assigning values to the key fields instead of setting a filter works with FIND(’-’). [:p] >>> Addendum: I just noticed you edited your posting, replacing the assignments with SETRANGEs…
A small point, but statements like recCrMemo.FIND(’-’); will return an error if a blank record set is returned. It should always have an IF statement around the statement. If you don’t want to handle situation al least put IF recCrMemo.FIND(’-’) THEN; The other mistake I often make is something like this IF recCrMemo.FIND(’-’) THEN REPEAT … UNTIL NEXT = 0; Don’t forget to put recCrMemo.NEXT = 0; It’s a bit off topic, but if I had a nickle…
Hi When you use just FIND it is the same as using FIND(’=’) which look for a record which has the same key value as the current record. You can also use FIND(’<’) which would find the record before what is set in the current key and FIND(’>’) which find the record after the current key fields. So in this case you wan to set the key fields you require and call FIND(’>’). As none of the primary key details are filled in you will get the first record that meets your specifactions. Just an off topic note about FIND. When you use SQL when you do a write transaction (ok I mean MODIFY) it must have been the last record to have been read (ok so I mean time stamp info is also stored with the record). You can use a FIND to force a read of the current record and so use modify. Paul Baxter