Tech Tip: Utility method that list a list item for a given path
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: August 2, 2013
Here is a utility method that provides the ability to select a list item on a form programmatically:
// ---------------------------------------------------- // Method: UTIL_SELECT_LIST_ITEM // Description // This method select a list item based on the given path // or name. // // Parameters // $1 - List Reference // $2 - Name or Path (Item/Item/Item) // $3 - Main List Reference // ---------------------------------------------------- C_LONGINT($1;$list_l) C_TEXT($2;$itempath_t) C_LONGINT($3;$mainlist_l) C_LONGINT($pos_l;$listpos_l) C_TEXT($search_for_t;$itemname_t) If (Count parameters>=2) $list_l:=$1 $itempath_t:=$2 If (Count parameters>=3) $mainlist_l:=$3 Else $mainlist_l:=$list_l End if $pos_l:=Position("/";$itempath_t) If ($pos_l>1) $search_for_t:=Substring($itempath_t;1;$pos_l-1) Else $search_for_t:=$itempath_t End if If ($search_for_t#"") $itemRef_l:=">Find in list($list_l;$search_for_t;1;*) $listpos_l:=List item position($list_l;$itemRef_l) GET LIST ITEM($list_l;$listpos_l;$itemRef_l;$itemname_t;$subList_l) If ($itemname_t#$itempath_t) & ($subList_l#0) If (Count list items($subList_l)>0) $itempath_t:=Delete string($itempath_t;1;$pos_l) UTIL_SELECT_LIST_ITEM ($subList_l;$itempath_t;$mainlist_l) End if Else $listpos_l:=List item position($mainlist_l;$itemRef_l) SELECT LIST ITEMS BY POSITION($mainlist_l;$listpos_l) End if End if End if |
Here is an example:
UTIL_SELECT_LIST_ITEM(HList;"Company")
UTIL_SELECT_LIST_ITEM(HList;"Company/Technical Support")
UTIL_SELECT_LIST_ITEM(HList;"Company/Sales/Inside/John Smith")