4D v18 R4 and ORDA made it possible for you to create high-level class functions above the data model. This allows you to write business-oriented code to hide complexity, reduce errors, and speed up the development process.
With 4D v18 R5, we’re bringing even more features to help you optimize and organize your code. For example, you might need to run a function locally on the client to improve performance when working in client/server mode. It’s now possible! Or if you expose your database as a REST server, you might want some functions to be available on the server-side but hidden for your REST clients. This is also possible!
Two new keywords for functions in ORDA data model classes are available:
working in C/S with the LOCAL keyword
Functions are executed on the server by default in C/S, but you can now choose to execute some of them on the client. This can greatly improve performance.
In this example, we have a Students dataclass. Let’s write a function that returns the student’s ages.
Here is our age() function in the cs.StudentsEntity entity class.
Class extends Entity
// This is an estimate of the age
local Function age() : Variant
$0:=Year of(Current date)-Year of(This.birthDate)
And this is a list box displaying all the students with the age column mapped with the expression This.age():
Thanks to the local keyword, the age() function is executed locally on the client with the birthdate loaded while displaying the list box. This is important to be in tune with the 4D v17 R5 ORDA requests optimization.
Without the local keyword, the age() function would trigger a request to the server for each line!
You can use the exposed keyword to have a function published as an API for REST clients.
In the example below, the registerNewStudent() function in the cs.Students dataclass class is callable from a REST client while computeStudentId() is not.
Class extends DataClass
exposed Function registerNewStudent($student : Object) : Object
var $entity : cs.StudentsEntity
var $status : Object
// This function not callable from a REST client
Function computeStudentId() : Integer
//compute a new student Id
Here is the calling code on the REST client:
var $connect;$ds;$student;$result : Object
var $studentId : Integer
$connect:= New object("hostname";"127.0.0.1:8044")
$student:=New object("firstname"; "Mary"; "lastname"; "Smith")
// Execution is OK, no error is raised
//An error is raised
Check out the documentation and the HDI above to learn more about the new features!