Tip #38 | SETSELECTIONFILTER to SETFILTER


This week I got a question from one of my book readers about how to convert a SETSELECTIONFILTER to a SETFILTER command.

This is something that is implemented in the standard product on a few list pages. The Customer List page (22) is one of them.

The code is handled in codeunit 46, SelectionFilterManagement

This is the code:

 RecRef.OPEN(TempRecRef.NUMBER);
 TempRecRefCount := TempRecRef.COUNT;
 IF TempRecRefCount > 0 THEN BEGIN
   TempRecRef.FIND('-');
   WHILE TempRecRefCount > 0 DO BEGIN
     TempRecRefCount := TempRecRefCount - 1;
     RecRef.SETPOSITION(TempRecRef.GETPOSITION);
     RecRef.FIND;
     FieldRef := RecRef.FIELD(SelectionFieldID);
     FirstRecRef := FORMAT(FieldRef.VALUE);
     LastRecRef := FirstRecRef;
     More := TempRecRefCount > 0;
     WHILE More DO
       IF RecRef.NEXT = 0 THEN
         More := FALSE
       ELSE BEGIN
         SavePos := TempRecRef.GETPOSITION;
         TempRecRef.SETPOSITION(RecRef.GETPOSITION);
         IF NOT TempRecRef.FIND THEN BEGIN
           More := FALSE;
           TempRecRef.SETPOSITION(SavePos);
         END ELSE BEGIN
           FieldRef := RecRef.FIELD(SelectionFieldID);
           LastRecRef := FORMAT(FieldRef.VALUE);
           TempRecRefCount := TempRecRefCount - 1;
           IF TempRecRefCount = 0 THEN
             More := FALSE;
         END;
       END;
       IF SelectionFilter <> '' THEN
         SelectionFilter := SelectionFilter + '|';
       IF FirstRecRef = LastRecRef THEN
         SelectionFilter := SelectionFilter + AddQuotes(FirstRecRef)
       ELSE
         SelectionFilter := SelectionFilter + AddQuotes(FirstRecRef) + '..' + AddQuotes(LastRecRef);
       IF TempRecRefCount > 0 THEN
         TempRecRef.NEXT;
     END;
   EXIT(SelectionFilter);
 END;

In older versions than 2013, this code is on the page/form object.

Enjoy!

Advertisements
This entry was posted in Tips and Tricks. Bookmark the permalink.

2 Responses to Tip #38 | SETSELECTIONFILTER to SETFILTER

  1. TheDoubleH says:

    It is also used on the G/L Account List, and is very useful when creating Account Schedules. It enables the user to simply highlight the accounts required for each line.

    Like

  2. Pingback: Tip #38 | SETSELECTIONFILTER to SETFILTER | Pardaan.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s