Changing country sorting in the lookup

Question

Kindly advise how I can put "Ukraine" at the top of the list in the [Countries] lookup (not a drop-down list).

Answer

Create a "Country" replacing object and add a UsrSort (Priority) integer column with the "0" default value therein.

Add and execute an SQL script in the configuration, which will arrange the priority as you need it - Ukraine will come first and all the rest of the countries will be arranged in the alphabetical order:

Script text:

UPDATE Country SET UsrSort = 0 WHERE Name = 'Ukraine'
 
DECLARE @sort INT
DECLARE @id uniqueidentifier
DECLARE @getid CURSOR
 
SET @sort = 1
SET @getid = CURSOR FOR
SELECT Country.Id FROM Country
WHERE Name Not In ('Ukraine')
ORDER BY Name
 
OPEN @getid
FETCH NEXT
FROM @getid INTO @id
WHILE @@FETCH_STATUS = 0
BEGIN
    UPDATE Country SET UsrSort = @sort WHERE Id = @id
    SET @sort = @sort + 1
    FETCH NEXT
    FROM @getid INTO @id
END
 
CLOSE @getid
DEALLOCATE @getid

You can later on display this column in the record list via the "View" - "Select fields to display" and use it for sotring via "View"- "Sort by".

Like 0

Like

Share

0 comments
Show all comments