KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method to Convert Collection to Text
PRODUCT: 4D | VERSION: 17 R | PLATFORM: Mac & Win
Published On: November 21, 2019

Below is a utility method that will convert a collection passed as the first and only parameter to a full text string.

  // ----------------------------------------------------
  // Method: CollectionToText
  // Description
  // Converts a collection to a text
  //
  // Parameters
  // $1 - Collection to be converted to a String
  //
  // $0 - Text to contain the result
  //
  // ----------------------------------------------------


C_TEXT($0)
C_COLLECTION($1)
C_OBJECT($varObject)

If (Count parameters=1)
  If ($1#Null)
    $varObject:=New object("col";$1)
    $0:=JSON Stringify array($varObject.col)
  End if
End if


Example Use:
C_COLLECTION($inputCollection)
C_TEXT($resultText)

$inputCollection:=New collection()
$inputCollection.push(123)
$inputCollection.push("Hello")
$inputCollection.push(Current date)
$inputCollection.push(True)
$inputCollection.push(Null)

$resultText:=CollectionToText($inputCollection)


Result:


This can be useful if a collection needs to be outputted to a text document or transfered somewhere where text is useful to handle the data.