KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to handle entity selections with WEB SEND TEXT
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: November 15, 2018

When trying to use WEB SEND TEXT with entity selections, the typical first approach would be to use JSON Stringify to convert the entity selection to text. However, entity selections are objects containing references to entities which do not directly translate to text format from JSON Stringify. Attempting this type of conversion leads to the following text below which cannot be JSON parsed correctly back to usable data. An example is provided using a table named People.

$peopleJSON_t:=JSON Stringify(ds.People.all())




Attempting to JSON PARSE ARRAY the text also does not generate the expected results.

JSON PARSE ARRAY($peopleJSON_t;$people_ao)




Instead of directly converting entity selection to text, first convert the entity selection to a collection and convert that collection to text using the line below.

$peopleJSON_t:=JSON Stringify(ds.People.all().toCollection())


Now using WEB SEND TEXT will generate the expected text and can successfully be parsed back into an array using JSON PARSE ARRAY if needed.

WEB SEND TEXT($peopleJSON_t)