KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method for saving lists to a table
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: April 18, 2022

When working in project mode, lists will no longer be modifiable in client-server and compiled .4DZ. As an alternative, this utility method below can be used to convert the existing lists to records in a table.

// Method: convertListsToRecords
// Description
// Converts existing lists to table records
//
// Parameters
// $1 - Destination table: POINTER
// $2 - Field for list name: POINTER
// $3 - Field for list blob data: POINTER
// ----------------------------------------------------

C_POINTER($1; $table_ptr)
C_POINTER($2; $listNameField_ptr)
C_POINTER($3; $listBlobField_ptr)

C_TEXT($listPath_t)
C_TEXT($listName_t)
C_OBJECT($listJson_o)
C_OBJECT($e)
C_LONGINT($listRef_l)
C_BLOB($test)

If (Count parameters>=3)
  
   $table_ptr:=$1
   $listNameField_ptr:=$2
   $listBlobField_ptr:=$3
  
   $listPath_t:=Get 4D folder(Database folder)+"Project"+Folder separator+"Sources"+Folder separator+"lists.json"
  
   If (Test path name($listPath_t)=Is a document)
   $listJson_o:=JSON Parse(Document to text($listPath_t))
  
   For each ($listName_t; $listJSON_o)
     CREATE RECORD($table_ptr->)
     $listNameField_ptr->:=$listName_t
     $listRef_l:=Load list($listName_t)
     LIST TO BLOB($listRef_l; $listBlobField_ptr->)
     SAVE RECORD($table_ptr->)
  
   End for each
  
   End if
  
   ALERT("Done")
  
End if


Now instead of trying to save the list to the structure using SAVE LIST, the list can be converted to a BLOB and saved directly to the table.