RavCOder
12th September 2019, 10:23
Hi,
I have a doubt about insert a record in table with DAL: I see in the programmer's guide that there is a method call db.insert(), but it's not correct for DAL.
What is the right procedure to insert a record in a table in a DAL?
Regards,
RavCoder
bdittmar
12th September 2019, 12:28
dal.save.object()
Syntax:
function long dal.save.object (string tbl.name [, long error.flag])
Description
Saves a record of the given table. In case a dal.new.object() or a dal.copy.object() was done, the record is inserted in the database. In case a dal.change.object() was done, the record is updated in the database.
In case DAL2 Field dependencies have been defined in the DAL, this function takes care that dependent fields will be triggered in the right order so that they can update themselves.
Note that this is done based on the values of the fields that have been set by calling dal.set.field()
Before the record is saved all (changed) fields will be validated.
The sequence of the actions is as follows:
Table level permission is checked.
For all fields set, the fieldname.make.valid() is executed, e.g. to perform rounding of data.
All dependent fields are triggered to update themselves.
Record level permission is checked.
The actual save (insert or update) is done.
Arguments
string tbl.name the table name of the DAL.
[long error.flag ]
Return values
0 Record is saved
DALHOOKERROR One of the hooks blocked the save action
DALDBERROR A domain or reference error occurred (only in Integration context (e.g. via a BOL))
DALNOSETPERM No table level permission
DALNOOBJPERM No record level permission
>0 The error code of the db.insert() or db.update() function
Context
This function can be used in all script types.
Hooks called
before.open.object.set() if this is the first call to the DAL
after.new.object() in case of a new record
after.change.object() in case of an existing record
for all fields set, the fieldname.make.valid() hook is executed
for each dependent field:
field.update()
method.is.allowed()
for each (DAL_NEW) / each changed (DAL_UPDATE) field:
one or more field hooks
before.save.object()
after.save.object()
Error Handling
In case a database error occurs (a return value greater than 0), then this function will set an error message. E.g. in case a record is modified by another user then an error message is set.
Note
When working with DAL2 DALs, it is advised to use dal.save.object() instead of dal.new() or dal.update(). Only then field dependencies are taken into account.
In case the DAL does not have field dependencies defined, or if you don't want to set defaults based on field dependencies, you can also use dal.new() or dal.update(). These functions are faster than dal.save.object().
Regards
RavCOder
12th September 2019, 12:52
Hi,
Thanks for your help.
I created a DAL but in the DAL script I have two functions : before.open.object.set() and before.save.object (long type). I don't understand what I have to put into.
Regards,
RavCoder
RavCOder
12th September 2019, 13:36
I understand I set fields in the function before.open.object.set().
Now I have to call this DAL in a print session that I have created (tdsls4900m000).
How can I do?
andreas.toepper
12th September 2019, 16:11
You don't need to "call" a DAL. (It’s like a library, but the functions declared are executed automatically.)
The functions you see when creating a new DAL script are called “hooks”. Hooks are not called manually in a function. They are called automatically (“in the background”) when you update or create a dataset of a given table.
So, if you want to update a dataset in a print session (like mark a set as printed), you need to modify the dataset. To invoke DAL hooks, you need to use the correct standard functions:
|An example:
db.retry.point()
dal.change.object("tiipd001")
dal.set.field("tiipd001.oltm", new.value)
dal.save.object("tiipd001")
commit.transaction()
This will call the defined hooks of the table on runtime.
RavCOder
12th September 2019, 16:46
Ok I have already entered those things and I put in the session script program the DAL but if I try to start the session it doesn't start anything (this doesn't show it to me).