Sort by/View options

The Sort by/View options button drop list allows the user to specify the order in which records will be displayed in the lookup window. It also allows the contents of the scrolling window to be refreshed and toggled between normal and detail modes. A typical Sort by/View options menu is shown in the following illustration.

[spacer]

The contents of this button drop list is specified dynamically through sanScript code. The items correspond to keys in the scrolling window’s linked table. When the user selects an item in the sort list, the lookup window’s scrolling window is filled using the selected key.

Adding a Sort by/View options list

To add a Sort by/View options button drop list to a lookup window, use the following procedure.

  1. Create the sort list/view options field.

Create a local field named ‘Sort By’ for your lookup form. This local field has the following characteristics:

[spacer]

Field Name

Sort By

Control Type

Button Drop List

Static Type

Text


Use the image named SortBy_DownArrow from the Dynamics.dic dictionary as the Up, Down and Over Image for the button drop list field.

  1. Add the Sort By field to the lookup window.

Set the following Object properties for the field:

[spacer]

SavedOnRestart

True

SetChangeFlag

False

TabStop

False


Set the following Visual properties for the field:

[spacer]

Alignment

Left

Appearance

3D Highlight

BackColor

System - List Header1

Border

True

FontColor

System - List Header1 Text

Style

Text on Right


  1. Attach a change script.

Attach a change script to the Sort By field similar to the following example. This script sets the Sort By field to indicate what key to use when displaying records in the lookup window. It also handles refreshing the contents of the scrolling window and toggling between normal and detail mode.

local boolean result;
local integer i;

{Which group of items was selected? If it's less than 4, a sorting item was selected.}
if '(L) Sort By' < 4 then
	{Set the Sort By button drop list.}
	result = Field_SetCaption('(L) Sort By', "&View: All " + itemname('(L) Sort By', '(L) Sort By'));

	{Set the caption for the 'Find'.}
	'(L) Find Prompt' = "Find " + itemname('(L) Sort By', '(L) Sort By');

	{Mark the appropriate item in the Sort By button drop list.}
	for i = 1 to countitems('(L) Sort By') do
		uncheck field '(L) Sort By', i;
	end for;
	check field '(L) Sort By', '(L) Sort By';

	{Fill the scrolling window.}
	fill window Lead_Lookup_Scroll by number '(L) Sort By';
else
	{One of the display options was selected.}
	if '(L) Sort By' = 5 then
		{Redisplay}
		'(L) Sort By' = old();
		run script 'Redisplay Button';
	elseif '(L) Sort By' = 7 then
		{Show detail}
		'(L) ShrinkExpandSwitch' = 2;
		run script '(L) ShrinkExpandSwitch';
	elseif '(L) Sort By' = 8 then
		{Hide detail}
		'(L) ShrinkExpandSwitch' = 1;
		run script '(L) ShrinkExpandSwitch';
	end if;
end if;

  1. Attach a form pre script.

Attach a form pre script to the lookup form similar to the following example. This script adds items to the Sort List, then runs the sort list’s change script, automatically filling the lookup window’s scrolling window.

local boolean result;

add item "by Lead ID" to '(L) Sort By' of window 'Lead Lookup';
add item "by Lead Name" to '(L) Sort By' of window 'Lead Lookup';
add item "by Salesperson" to '(L) Sort By' of window 'Lead Lookup';
add item "-" to '(L) Sort By' of window 'Lead Lookup';
add item "Refresh" to '(L) Sort By' of window 'Lead Lookup';
add item "-" to '(L) Sort By' of window 'Lead Lookup';
add item "Show Detail" to '(L) Sort By' of window 'Lead Lookup';
add item "Hide Detail" to '(L) Sort By' of window 'Lead Lookup';
set '(L) Sort By' of window 'Lead Lookup' to 'Sort By' of window 'Lead Maintenance' of form IG_Lead_Maintenance;
run script '(L) Sort By' of window 'Lead Lookup';

{Set the Shrink/Expand button.}
set '(L) ShrinkExpandSwitch' of window 'Lead Lookup' to 1;
redraw field '(L) ShrinkExpandSwitch' of window 'Lead Lookup';
result = Field_SetToolTip('(L) ShrinkExpandSwitch' of window 'Lead Lookup' ,"Show Details");


Documentation Feedback