As you probably know, computed attributes are available starting from 4D v19 R3. A blog post is available that presents this great new feature.
As we always propose the best and complete user experience to our mobile app developers, computed attributes are compatible with all your iOS and Android projects.
This means that as soon your getters are defined, you can use them as any other field in your mobile app creation process. So you’ll be able to visualize and publish them from the Structure section of the mobile project editor. This is a considerable improvement when it comes to displaying more relevant information in your mobile app, avoiding splitting an address into several fields for example.
Let’s see how it works with an example. We’ll display a computed fullname field with a first name and last name and a fulladdress computed field using a street number, city, and country fields.
4D side
As you can see in the structure, a FirstName and a LastName attributes are available. We want to display “FirstName LastName” in our mobile app.
In the same way, we have a StreetNumber, an Address, and a Location attributes. And we want to display “StreetNumber Address – Location.”
For that, let’s extend the ContactEntity class:
Class extends Entity exposed Function get fullName->$result : Text $result:=This.FirstName+" "+This.LastName exposed Function get fullAddress->$result : Text $result:=This.StreetNumber+" "+This.Street+" - "+This.Location
Now let’s go back to the mobile project editor.
Project editor side
As you can see in the project editor, your computed attributes are now available from the structure section, ready to be published and used as any other field in the creation process.
This means that you can use them in the Data section to filter your data, add an icon, as well as short and long labels. You can also use them as action parameters as soon as a setter is available. Still, in this example, it was more relevant to use single attributes in action forms to make editing easier.
Now let’s build our app!
Mobile app side
In our final app, both single attributes and computed attributes are displayed.
So as you can see, this new feature allows more advanced use of the existing templates and displays more information in a relevant way.
Don’t hesitate to give us feedback on the 4D forum, and check out the documentation for more details!