4D Blog

Home Product Move to shareable entity selections smoothly

Move to shareable entity selections smoothly

December 17, 2020

Product

In this blog post, you discovered the power that shareable entity selections can offer. 4D focuses on data sharing because, in the long run, it leads to performance.

But we’re aware that this strategy might not be your current strategy. We’ve followed the discussions on the forum and understood your comments and feelings.

To soften this step and give you more flexibility and tools, we’ve made some enhancements regarding the nature (shareable or non-shareable) of entity selections.

Before continuing, we highly recommend that you read this blog post and this one so you can make sense of the enhancements described below.

HDI: Entity selections enhancements

4D v18 R5 offers more possibilities to handle non-shareable (alterable) entity selections. It helps you work the way you’re used to.

On the other hand, if you’re willing to work with shareable entity selections, we’ve helped you to get prepared for this new era in 4D v18 R5. In 4D v18, we’ve introduced a flexible way that you can use transparently to prepare your code.

In a nutshell: prepare in 4D v18, run in 4D v18 R5, and get ready for more performance!

about alterable entity selections

add an entity to an entity selection

A frequent use case is displaying an entity selection in a list box (products, invoices, etc.) and allow the user to add new ones.

Let’s work on a Products dataclass.

When the form is loaded, Form.products is created, it’s the datasource of the list box:

Case of
: (Form event code=On Load)
    Form.products:=ds.Products.all()
End case

When the user adds a new product:

Form.products.add(Form.product)

If you run this code as is in 4D v18 R5, you’ll get an error when running the add() function because ds.Products.all() returns a shareable entity selection (not alterable).

We’re aware of this inconvenience. That’s why you’ll find that the 4D v18 copy() function is available to prepare your code to get ready for 4D v18 R5.

If copy() is run in 4D v18: it just copies your entity selection

If copy() is run in 4Dv18 R5, by default, it copies your non-alterable entity selection as an alterable one so that you’ll get no problem with the add action!

So just prepare your code like this:

Case of
: (Form event code=On Load)
   Form.products:=ds.Products.all().copy()
End case

retain the nature of entity selections

Entity selections created from an original entity selection keep the same nature.

examples

Sort a list box

Let’s work again on the example of displayed products. This displayed entity selection has been set as alterable because the user needs to add new products.

Any sort of action on the list box columns keeps the alterable nature of the entity selection so that you can still add products.

Run a query

If you run a query on an entity selection, the nature of the entity selection is kept for the result.

In our example, if the user runs a search on the displayed products:

Form.products:=Form.products.query("name = :1"; Form.search)

The result of the query is alterable so new products can still be added because Form.products is alterable.

These are only two examples. Check the documentation to verify all of the cases where the nature of the original selection is kept. 

generic code

It can be useful to check the nature of an entity selection in generic code in order to use it in the appropriate way. Imagine a method receiving an entity selection that can be either shareable or not.

In the example below, we receive a Products entity selection. Before passing it to a WORKER, we must check to see if it is shareable. If it’s not, we turn it into a shareable entity selection.

For this, we use the new OB Is shared() function.

var $products; $1 : cs.ProductsSelection
$products:=$1

If (Not(OB Is shared($products)))
  $products:=$products.copy(ck shared)
End if
//Generate the catalog of products
CALL WORKER("worker"; "buildCatalog"; $products; Current form window)

Note: There is also a new isAlterable() function available on entity selections to check if they are alterable.

Download the HDI above for more examples!

Keep working as before

If you want to continue the behavior of previous 4D versions (without any concepts of shareable entity selections), you can use the makeSelectionsAlterable() class function available on the datastore object.

This will make the changes brought with 4D v18 R5 completely transparent for you.

Discuss

Tags ORDA, Shareable, v18 R5, v19

Latest related posts

  • June 16, 2025

    Generate, share and use web sessions One-Time Passcodes (OTP)

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

Avatar
Marie-Sophie Landrieu-Yvert
• Product Owner • Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy