We’ve all been there. You build a beautiful interface that displays an entity selection for users. They can drop entities to refine their choices, but then… those empty spaces appear where the dropped entities used to be.
Rebuilding the entity selection after drops? No more! 4D 20 R6 introduces a handy feature that eliminates this pain point with just one line of code.
Keep reading to discover how this feature can keep your interface clean and your users happy.
the clean function on the entity selection object
Let’s dive into how this feature works.
An entity selection is displayed, and the user can delete some entities.
The list box below displays the Form.persons entity selection. The user selects some of them (Form.selected) and click on a Drop button. If we run only this code:
Form.selected.drop()
Form.persons:=Form.persons
We get this:
With just one line of code, thanks to the new clean() function:
Form.persons:=Form.persons.clean()
The empty spaces are magically gone, leaving your interface clean and user-friendly:
The clean parameter in the $entityset REST API
If your application relies on REST APIs, you can also use the clean parameter with the $entityset REST API.
If you have an entity set containing deleted entities (as featured by the blue object containing the __STAMP property) like this one:
{
"__DATACLASS": "Persons",
"__entityModel": "Persons",
"__GlobalStamp": 0,
"__COUNT": 3,
"__FIRST": 0,
"__ENTITIES": [
{
"__STAMP": 0
},
{
"__KEY": "2",
"__TIMESTAMP": "2024-05-23T09:26:19.658Z",
"__STAMP": 1,
"ID": 2,
"firstname": "Broddy",
"lastname": "Cristofanini"
},
{
"__KEY": "3",
"__TIMESTAMP": "2024-05-23T09:26:19.658Z",
"__STAMP": 1,
"ID": 3,
"firstname": "Candie",
"lastname": "Figin"
}
],
"__SENT": 3
}
You can get a new entity set without the deleted entities by running the request below (949062617AF6408CB198B3CB41FB72FB is the entity set ID):
/$entityset/949062617AF6408CB198B3CB41FB72FB?$clean=true&$method=entityset
The result? An entity set without the deleted entries:
{
"__ENTITYSET": "/rest/Persons/$entityset/8F658F3BA1884DE6BEC1FCFF4A7938F0",
"__DATACLASS": "Persons",
"__entityModel": "Persons",
"__GlobalStamp": 0,
"__COUNT": 2,
"__FIRST": 0,
"__ENTITIES": [
{
"__KEY": "2",
"__TIMESTAMP": "2024-05-23T09:47:50.933Z",
"__STAMP": 1,
"ID": 2,
"firstname": "Broddy",
"lastname": "Cristofanini"
},
{
"__KEY": "3",
"__TIMESTAMP": "2024-05-23T09:47:50.933Z",
"__STAMP": 1,
"ID": 3,
"firstname": "Candie",
"lastname": "Figin"
}
],
"__SENT": 2
}
With this new feature, managing entity selections has never been easier. Keep your interfaces tidy and your users happy!